Repository navigation
Description
Target Language
rust
Query Name (Optional)
CredentialAndDataExposure
Query Type
Security
Query Description
AI Scan reported 8 medium-severity CWE-321, CWE-532 (credential and data exposure) finding(s) in Rust public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-query, query-logic. Existing queries considered: rust/cleartext-logging.
Why CodeQL appears to have missed these (unverified until reproduced with a test database):
- The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- The query exists, but a freshly generated key printed with println may need stronger key-material recognition and logging-sink coverage.
Linked findings (gap-key: rust/query-create/credential-and-data-exposure)
| Repo | CWE | Severity | AI scan alert | Summary |
|---|---|---|---|---|
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/3 | The encryption and decryption passphrase is embedded in source. Anyone with repository or binary access can recover it and decrypt data protected by this application; load the secret from a protected runtime secret store instead. |
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/5 | The AES key is a fixed literal sequence committed to source. All ciphertexts use a key an attacker can recover from the application, eliminating confidentiality. |
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/6 | The AES key is a fixed repeated value in source. This key is recoverable from source or the executable and must be replaced with securely managed key material. |
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/7 | The AES-192 key is a literal sequential byte array in source. An attacker can reconstruct this key and decrypt or forge protected data. |
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/8 | The Camellia key is a fixed all-zero byte array. It is predictable and embedded in the executable, so it provides no secret protection. |
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/9 | A fixed byte array is used as the AEAD secret key. Attackers who obtain the source or binary can decrypt ciphertexts and generate valid ciphertexts. |
| rust-vulnerable-apps | CWE-321 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/10 | The shared authentication key is embedded as a literal. Anyone with code or binary access can create valid authentication tags and impersonate a trusted party. |
| rust-vulnerable-apps | CWE-532 | medium | https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/26 | The AES-256-GCM key is hex-encoded and printed. In deployed applications stdout is commonly retained in shared logs or exposed to log readers, allowing recovery of the encryption key and decryption or forgery of data from that run. |
Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.
Handling decision
- Type: Query Create
- Decision: Create a new CodeQL query. No existing query covers these patterns (most findings are gap type
query-absentormissing-query). Because coverage of lower-severity patterns can be heuristic, target Community Packs unless precision is shown to be high enough for github/codeql. - Recommended actions across the findings: write-new-query (7), extend-existing-query (1)
Patterns in this gap
missing-query(7 findings), for example rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_01_age/src/main.rsquery-logic(1 finding), for example rust-vulnerable-apps hardcoded_secret/hardcoded_secret_good_02_ring/src/main.rs
Finding details
Each finding below has its own context so the agent can work from this issue alone.
1. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_01_age/src/main.rs:51 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/3
- AI Scan message: The encryption and decryption passphrase is embedded in source. Anyone with repository or binary access can recover it and decrypt data protected by this application; load the secret from a protected runtime secret store instead.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
2. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_03_aes/src/main.rs:16 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/5
- AI Scan message: The AES key is a fixed literal sequence committed to source. All ciphertexts use a key an attacker can recover from the application, eliminating confidentiality.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
3. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_04_aes/src/main.rs:16 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/6
- AI Scan message: The AES key is a fixed repeated value in source. This key is recoverable from source or the executable and must be replaced with securely managed key material.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
4. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_05_aes/src/main.rs:14 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/7
- AI Scan message: The AES-192 key is a literal sequential byte array in source. An attacker can reconstruct this key and decrypt or forge protected data.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
5. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_06_camellia/src/main.rs:13 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/8
- AI Scan message: The Camellia key is a fixed all-zero byte array. It is predictable and embedded in the executable, so it provides no secret protection.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
6. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_07_orion/src/main.rs:21 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/9
- AI Scan message: A fixed byte array is used as the AEAD secret key. Attackers who obtain the source or binary can decrypt ciphertexts and generate valid ciphertexts.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
7. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_bad_08_orion/src/main.rs:13 (CWE-321, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/10
- AI Scan message: The shared authentication key is embedded as a literal. Anyone with code or binary access can create valid authentication tags and impersonate a trusted party.
- Why CodeQL appears to miss it: missing-query: The Rust catalog has weak-algorithm and weak-hashing queries but no query for literal cryptographic keys or passphrases flowing to crypto constructors.
- Recommended action from the comparison: write-new-query (classification confidence: high)
8. rust-vulnerable-apps hardcoded_secret/hardcoded_secret_good_02_ring/src/main.rs:50 (CWE-532, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/26
- AI Scan message: The AES-256-GCM key is hex-encoded and printed. In deployed applications stdout is commonly retained in shared logs or exposed to log readers, allowing recovery of the encryption key and decryption or forgery of data from that run.
- Why CodeQL appears to miss it: query-logic: The query exists, but a freshly generated key printed with println may need stronger key-material recognition and logging-sink coverage.
- Existing CodeQL queries considered: rust/cleartext-logging
- Recommended action from the comparison: extend-existing-query (classification confidence: medium)
Expected Severity
Medium
Code Examples
See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.
CWE/CVE Reference (Optional)
CWE-321, CWE-532
References (Optional)
https://cwe.mitre.org/data/definitions/321.html
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
felickz commentedon Nov 3, 2026
Upstream triage
precision:mediumRelies on heuristics or accepted over-approximation. Community Packs, always tags:experimental.
tags:experimental
Goes to Community Packs: performance, false-positive or synthetic-only concerns.
Community Packs, experimental. Recommended for the Community Packs repository, not
github/codeql. The issue is labeledtags:experimentalfor this.Linked pull request: #322
Why. Two new queries. The hard-coded key query extends the stock rust/hard-coded-cryptographic-value query with age, orion and ring sinks and an unresolved-From step; hard-coded credential queries are not taken upstream, so it fits Community Packs. The logging query reports generated keys that also reach a key sink, which flags key-generation tools that print keys on purpose, so precision is medium. Prefer model rows over path regexps.
mediumin the pull request). Logging query ties a generated-key heuristic (RNG fill, generate_key) to a key sink; fallible-RNG barrier is an accepted limitation. Key query uses regexps over canonical paths and an unresolved X::from step (CryptoKeyMaterial.qll).Concerns, overlap and next steps
False-positive concerns
Performance concerns
Heuristics used
What an upstream change would look like. Community Packs: rust/src/<category>/ for both queries plus the shared library, tests under rust/test; the age, orion and ring sinks as credentials-key and credentials-password rows in rust/ext/manual. Nothing for github/codeql under the hard-coded secrets policy.
Before opening an upstream pull request
Split note. Hard-coded key query and the age, orion and ring sinks are hard-coded credential coverage (Community Packs only). The logging query is a separate audit-grade idea; keep both experimental.
This is a recommendation only. A human reviews it before any pull request is opened against
github/codeqlor the Community Packs repository.