Repository navigation
Conversation
1 task done
… tests Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add new query for credential and sensitive data exposure
[NEW QUERY] Rust: hard-coded cryptographic keys (CWE-321) and logging of generated key material (CWE-532)
Oct 31, 2026
Copilot stopped reviewing on behalf of
felickz due to an error
November 2, 2026 18:57
There was a problem hiding this comment.
🟡 Changes recommended
RNG and key-flow handling can cause missed findings and false alerts, while dependency and installer configuration issues prevent reliable pack setup.
6 open issues
Correlate key and logging flows by generated value · New Recognize KeyInit::generate_key results as key material · New Require successful fallible RNG calls before treating buffers as overwritten · New Recognize concrete rand and rand_core trait calls · New Add Rust to the pack installer’s supported languages · New Pin codeql/rust-all to a CLI-compatible version · New
What changed in this PR
Adds the repository’s first custom Rust query pack to address the cryptographic-key exposure gaps described in #272, complementing existing CodeQL queries.
Changes:
- Adds queries for hard-coded keys and passphrases, and logging of generated key material.
- Introduces shared models for cryptographic APIs, conversions, random fills, and hex encoding.
- Adds regression fixtures, expected results, dependency locks, and documentation with safe and unsafe examples.
| File | Description |
|---|---|
languages/rust/example/.gitkeep |
Rust example directory placeholder. |
languages/rust/custom/test/qlpack.yml |
Defines the Rust test pack. |
languages/rust/custom/test/HardcodedCryptographicKey/test_ring.rs |
Tests ring keys and random initialization. |
languages/rust/custom/test/HardcodedCryptographicKey/test_orion.rs |
Tests Orion keys and passwords. |
languages/rust/custom/test/HardcodedCryptographicKey/test_camellia.rs |
Tests a constant Camellia key. |
languages/rust/custom/test/HardcodedCryptographicKey/test_age.rs |
Tests literal and runtime age passphrases. |
languages/rust/custom/test/HardcodedCryptographicKey/test_aes.rs |
Tests AES conversions and standard-query deduplication. |
languages/rust/custom/test/HardcodedCryptographicKey/options.yml |
Configures extraction and test dependencies. |
languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.qlref |
Connects fixtures to the hard-coded-key query. |
languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.expected |
Records expected alerts and paths. |
languages/rust/custom/test/HardcodedCryptographicKey/Cargo.lock |
Locks hard-coded-key test dependencies. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_ring.rs |
Tests key logging and non-secret output. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes.rs |
Tests debug and hex-encoded key logging. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes_gcm.rs |
Tests generated keys, nonces, and ciphertext. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/options.yml |
Configures extraction and logging-test dependencies. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qlref |
Connects fixtures to the logging query. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.expected |
Records expected logging alerts and paths. |
languages/rust/custom/test/CleartextLoggingOfKeyMaterial/Cargo.lock |
Locks logging-test dependencies. |
languages/rust/custom/test/.gitignore |
Excludes generated Rust test artifacts. |
languages/rust/custom/src/qlpack.yml |
Defines the custom Rust query pack. |
languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyGood.rs |
Demonstrates runtime-supplied key material. |
languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyBad.rs |
Demonstrates a hard-coded AES key. |
languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.ql |
Detects additional constant-key flows and deduplicates standard results. |
languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.qhelp |
Provides query help and remediation guidance. |
languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.md |
Documents hard-coded-key detection and examples. |
languages/rust/custom/src/common/CryptoKeyMaterial.qll |
Shares crypto sinks and key-material flow models. |
languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialGood.rs |
Demonstrates logging only key length. |
languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialBad.rs |
Demonstrates logging a generated key. |
languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.ql |
Detects generated material reaching key and logging sinks. |
languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qhelp |
Provides logging-query help and remediation. |
languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.md |
Documents key-logging detection and examples. |
languages/rust/custom/.gitkeep |
Rust custom directory placeholder. |
Review effort: Balanced
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📝 Query Information
rust/hardcoded-cryptographic-key,rust/cleartext-logging-key-material🎯 Description
The issue reported 8 medium-severity findings in synthetic Rust apps that default setup missed. I reproduced each one in a qltest database. Rust already has a hard-coded key query, so the premise "no query exists" is only partly right:
rust/hard-coded-cryptographic-value/rust/cleartext-loggingAes192::new_from_slice(&[0,1,..])GenericArray::from([..])Fromimpl isn't resolved, so taint stops atfromagepassphrase,orionSecretKey::from_slice,ringUnboundKey::new/hmac::Key::newringkey filled bySystemRandomand printed withhex::encodeSensitiveDatauses variable names and doesn't treatkey_bytesas secretNew pack:
languages/rust/custom/{src,test}Rust had no custom pack yet. I followed the layout of the other languages. The test
.gitignoreexcludes the generatedCargo.toml,lib.rsandtarget/.Cargo.lockis committed so dependency versions are reproducible.common/CryptoKeyMaterial.qllAdditionalCryptographicKeySink: sinks forage(with_user_passphrase,PassphraseDecryptor::decrypt),orion(SecretKey/Password::from_slice) andring(UnboundKey::new,hmac::Key::new,hkdf::Prk::new_less_safe).CryptographicKeySink: the sinks above plus the stdlibHardcodedCryptographicValue::Sink.keyMaterialConversionStep: flows throughT::from(x)calls whose target isn't resolved, and through thesecrecywrappers.randomFillCall/isRandomlyFilledBuffer: recognises calls that overwrite a buffer with random bytes.keyMaterialEncodingStep:hex::encodeandhex::encode_upper.isNonRevealingProperty:len,is_emptyandcapacity.rust/hardcoded-cryptographic-keyvec![0; n]followed byrand.fill(..)isn't reported.rust/hard-coded-cryptographic-valuealready reports are dropped.rust/cleartext-logging-key-materialgenerate_keyresult.CleartextLogging::Sink. Logging sinks includeprintln!,eprintln!and thelogmacros.key.len()aren't reported.Example vulnerable code
Example safe code
🧪 Testing
ringHMAC,orionpwhashandaes-gcmgenerate_key)env::var,getrandom,ringfill,orionSecretKey::default, nonce, ciphertext,len())rand/rand_corefills aren't covered yet, see below)Tests use inline expectations and
qltest_dependencies(they need network access to crates.io). With CLI 2.27.2 the lock files must pincodeql/rust-all0.2.23. 0.2.24's dbscheme failscodeql test run, and the lock files are gitignored, so anyone running the tests needs the same pin.📋 Checklist
.mdand.qhelp)The
randandrand_corepatterns inrandomFillCalluse canonical paths of the form<_ as …>. That form only appears for methods defined in blanket impls, soOsRng.fill_bytes(..)andrng.fill(..)never match. As a result:ringororionkey function can be falsely reported as hard-coded.Planned fix: change the patterns to
<([^>]+ as )?rand_core::RngCore>::(try_)?fill_bytesand<([^>]+ as )?rand::rng::Rng>::(try_)?fill, and addrandtest cases.🔗 References
rust/hard-coded-cryptographic-value,rust/cleartext-logging