Skip to content

[Query Create]: CWE-321, CWE-532 MEDIUM - Rust: new query for credential and sensitive data exposure #272

Open

Description

@felickz

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-absent or missing-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.rs
  • query-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

  1. added
    enhancement
    CWE-321
    severity:medium
    on Oct 31, 2026
  2. added
    precision:medium
    tags:experimental
    on Nov 3, 2026
  3. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:medium Relies 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 labeled tags:experimental for 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.

    Change New query
    Target Hard-coded crypto key sinks (age, orion, ring) and logged generated keys; extends rust/hard-coded-cryptographic-value
    Precision assessed medium (declared medium in 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).
    Real-world basis partial. Public crates age, orion, ring, aes, rand, getrandom, hex and secrecy are involved. Fixed keys are a real pattern; logging a generated key is real but intentional in key-generation tools.
    Stock overlap partial. Stock rust/hard-coded-cryptographic-value covers RustCrypto, cookie and biscotti key sinks (rust-all 0.2.21, grep); no age, orion or ring rows. rust/cleartext-logging has no generated-key source.
    Concerns, overlap and next steps

    False-positive concerns

    • Key-generation tools and examples that print a fresh key on purpose are reported by the logging query
    • Fixed keys in tests and known-answer vectors are reported by the hard-coded key query, as in stock
    • Unresolved X::from(arg) calls are assumed to keep key bytes, even for non-key values

    Performance concerns

    • callTo runs regexpMatch on the canonical path of every call target
    • Hard-coded key query re-runs the stock global flow to deduplicate results; logging query runs a flow plus a per-source key-sink check

    Heuristics used

    • regexps over canonical call-target paths (callTo) for age, orion, ring and RNG APIs
    • Unresolved calls named from treated as key-preserving conversions
    • Any RNG fill call argument is a barrier, including fallible calls

    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

    • Show a true positive on a real project for each query, not only the synthetic app
    • Replace callTo regexps with exact paths or credentials-key and credentials-password model rows
    • Decide how the logging query treats key-generation tools that print keys on purpose
    • Profile both queries on a large Rust database

    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/codeql or the Community Packs repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CWE-321CWE-532enhancementprecision:mediumquery-createseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions