Skip to content

[Data Extension Create]: CWE-327, CWE-328, CWE-338, CWE-780 MEDIUM - C/C++: data extension models for weak cryptography and randomness #276

Open

Description

@felickz

Target Language

cpp

Library Repository / Documentation URL

To be determined from the linked findings

Data Extension Name (Optional)

cwe-327, CWE-328, CWE-338, CWE-780.model.yml

Library Modules / Components

See linked findings for the frameworks involved.

Data Extension Description

AI Scan reported 4 medium-severity CWE-327, CWE-328, CWE-338, CWE-780 (weak crypto randomness) finding(s) in C/C++ public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-crypto-api-model-wincrypt, query-absent-weak-prng-security-use. Existing queries considered: cpp/weak-cryptographic-algorithm.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • 327 pattern: The bad() function derives a key with CALG_DES and decrypts data using CryptDecrypt with single DES (56-bit effective key). DES is cryptographically broken and brute-forceable; a modern algorithm such as AES should be used instead. Equivalent flaws exist in th
  • 328 pattern: The bad() function hashes the user-supplied password with CryptCreateHash(..., CALG_MD5, ...). MD5 is a broken, unsalted, fast hash that is trivially reversible via rainbow tables/collisions and must not be used for password or integrity protection.
  • 780 pattern: bad() encrypts a payload with an RSA key via CryptEncrypt() without specifying CRYPT_OAEP, so the legacy PKCS#1 v1.5 padding is used. PKCS#1 v1.5 encryption padding is vulnerable to Bleichenbacher-style adaptive chosen-ciphertext attacks; OAEP padding should b
  • 338 pattern: CWE338_Weak_PRNG__w32_01_bad() uses rand() to produce a value used as if it were random/unpredictable. rand() is a statistical, non-cryptographic PRNG whose output is predictable; use a CSPRNG (CryptGenRandom / getrandom / /dev/urandom) for any security-releva

Linked findings (gap-key: cpp/data-extension-create/weak-crypto-randomness)

Repo CWE Severity AI scan alert Summary
juliet-test-suite-c CWE-327 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/29 The bad() function derives a key with CALG_DES and decrypts data using CryptDecrypt with single DES (56-bit effective key). DES is cryptographically broken and brute-forceable; a modern algorithm such as AES should be used instead. Equivalent flaws exist in the sibling 3DES and RC5 test cases in this directory.
juliet-test-suite-c CWE-328 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/31 The bad() function hashes the user-supplied password with CryptCreateHash(..., CALG_MD5, ...). MD5 is a broken, unsalted, fast hash that is trivially reversible via rainbow tables/collisions and must not be used for password or integrity protection.
juliet-test-suite-c CWE-780 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/54 bad() encrypts a payload with an RSA key via CryptEncrypt() without specifying CRYPT_OAEP, so the legacy PKCS#1 v1.5 padding is used. PKCS#1 v1.5 encryption padding is vulnerable to Bleichenbacher-style adaptive chosen-ciphertext attacks; OAEP padding should be used instead.
juliet-test-suite-c CWE-338 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/30 CWE338_Weak_PRNG__w32_01_bad() uses rand() to produce a value used as if it were random/unpredictable. rand() is a statistical, non-cryptographic PRNG whose output is predictable; use a CSPRNG (CryptGenRandom / getrandom / /dev/urandom) for any security-relevant randomness.

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: Data Extension Create
  • Decision: Add a data extension (model-as-data). An existing query should report these once the library is modeled; add the missing sources, sinks, summaries or barriers as extension rows.
  • Recommended actions across the findings: add-data-extension (3), write-new-query (1)

Patterns in this gap

  • wincrypt-weak-algorithms (3 findings), for example juliet-test-suite-c testcases/CWE327_Use_Broken_Crypto/CWE327_Use_Broken_Crypto__w32_DES_01.c
  • weak-prng-rand (1 finding), for example juliet-test-suite-c testcases/CWE338_Weak_PRNG/CWE338_Weak_PRNG__w32_01.c

Finding details

Each finding below has its own context so the agent can work from this issue alone.

1. juliet-test-suite-c testcases/CWE327_Use_Broken_Crypto/CWE327_Use_Broken_Crypto__w32_DES_01.c:86 (CWE-327, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/29
  • AI Scan message: The bad() function derives a key with CALG_DES and decrypts data using CryptDecrypt with single DES (56-bit effective key). DES is cryptographically broken and brute-forceable; a modern algorithm such as AES should be used instead. Equivalent flaws exist in the sibling 3DES and RC5 test cases in this directory.
  • Why CodeQL appears to miss it: missing-crypto-api-model-wincrypt: 327 pattern: The bad() function derives a key with CALG_DES and decrypts data using CryptDecrypt with single DES (56-bit effective key). DES is cryptographically broken and brute-forceable; a modern algorithm such as AES should be used instead. Equivalent flaws exist in th
  • Existing CodeQL queries considered: cpp/weak-cryptographic-algorithm
  • Recommended action from the comparison: add-data-extension (classification confidence: medium)
2. juliet-test-suite-c testcases/CWE328_Reversible_One_Way_Hash/CWE328_Reversible_One_Way_Hash__w32_MD5_01.c:83 (CWE-328, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/31
  • AI Scan message: The bad() function hashes the user-supplied password with CryptCreateHash(..., CALG_MD5, ...). MD5 is a broken, unsalted, fast hash that is trivially reversible via rainbow tables/collisions and must not be used for password or integrity protection.
  • Why CodeQL appears to miss it: missing-crypto-api-model-wincrypt: 328 pattern: The bad() function hashes the user-supplied password with CryptCreateHash(..., CALG_MD5, ...). MD5 is a broken, unsalted, fast hash that is trivially reversible via rainbow tables/collisions and must not be used for password or integrity protection.
  • Existing CodeQL queries considered: cpp/weak-cryptographic-algorithm
  • Recommended action from the comparison: add-data-extension (classification confidence: medium)
3. juliet-test-suite-c testcases/CWE780_Use_of_RSA_Algorithm_Without_OAEP/CWE780_Use_of_RSA_Algorithm_Without_OAEP__w32_01.c:69 (CWE-780, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/54
  • AI Scan message: bad() encrypts a payload with an RSA key via CryptEncrypt() without specifying CRYPT_OAEP, so the legacy PKCS#1 v1.5 padding is used. PKCS#1 v1.5 encryption padding is vulnerable to Bleichenbacher-style adaptive chosen-ciphertext attacks; OAEP padding should be used instead.
  • Why CodeQL appears to miss it: missing-crypto-api-model-wincrypt: 780 pattern: bad() encrypts a payload with an RSA key via CryptEncrypt() without specifying CRYPT_OAEP, so the legacy PKCS#1 v1.5 padding is used. PKCS#1 v1.5 encryption padding is vulnerable to Bleichenbacher-style adaptive chosen-ciphertext attacks; OAEP padding should b
  • Recommended action from the comparison: add-data-extension (classification confidence: low)
4. juliet-test-suite-c testcases/CWE338_Weak_PRNG/CWE338_Weak_PRNG__w32_01.c:28 (CWE-338, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/30
  • AI Scan message: CWE338_Weak_PRNG__w32_01_bad() uses rand() to produce a value used as if it were random/unpredictable. rand() is a statistical, non-cryptographic PRNG whose output is predictable; use a CSPRNG (CryptGenRandom / getrandom / /dev/urandom) for any security-relevant randomness.
  • Why CodeQL appears to miss it: query-absent-weak-prng-security-use: 338 pattern: CWE338_Weak_PRNG__w32_01_bad() uses rand() to produce a value used as if it were random/unpredictable. rand() is a statistical, non-cryptographic PRNG whose output is predictable; use a CSPRNG (CryptGenRandom / getrandom / /dev/urandom) for any security-releva
  • Recommended action from the comparison: write-new-query (classification confidence: low)

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.

Additional References (Optional)

https://cwe.mitre.org/data/definitions/327.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

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

    @felickz
    Author

    Upstream triage

    precision:low Audit-grade or weak signal. 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: #326

    Why. Framed as data extensions, but the PR adds three new queries driven by custom extensible predicates, not rows for existing CodeQL models. SHA-1 and MD5 are flagged for any hash, RSA keys are tracked only from CryptGenKey and CryptDeriveKey, and the PRNG query flags every used rand() result. Stock cpp/weak-cryptographic-algorithm already matches DES and RC4 names. Suitable only as experimental Community Packs queries.

    Change New query
    Target New WinCrypt weak algorithm, RSA without OAEP and weak PRNG queries with custom extensible predicates
    Precision assessed low (declared high in the pull request). WeakPrng reports every used rand/random result (audit grade, declared low). WinCryptWeakAlgorithm flags any CALG_MD5/SHA1 hash, including non-security use (medium). The RSA query follows only CryptGenKey/CryptDeriveKey keys (medium, narrow).
    Real-world basis partial. Windows CryptoAPI (CryptCreateHash, CryptGenKey, CryptDeriveKey, CryptEncrypt) and libc rand/random are public, but the CryptoAPI is legacy, the RSA test builds its key with CryptDeriveKey, and CryptImportKey/CryptGetUserKey keys are not followed.
    Stock overlap partial. cpp/weak-cryptographic-algorithm matches DES/RC4/3DES names by regexp and likely covers part of WinCrypt calls; no stock weak-PRNG or RSA-padding query. Source review of cpp-queries 1.8.3, not run.
    Concerns, overlap and next steps

    False-positive concerns

    • CALG_SHA1 or CALG_MD5 used for HMAC, checksums or protocol compatibility is reported as a weak algorithm
    • rand() and random() are reported wherever the result is used, including simulation, tests and shuffling
    • RC4 or 3DES required by a fixed legacy protocol is reported with no way to tell it apart

    Heuristics used

    • Algorithm constants matched by macro or enum name (CALG_*)
    • PRNG functions matched by global name only (rand, random, drand48 family)
    • RSA keys tracked by local flow from CryptGenKey/CryptDeriveKey output only

    What an upstream change would look like. Community Packs cpp/src/<category>/ with three separate queries and tests in cpp/test/ (keep the stub wincrypt.h). The custom extensible predicates do not map to github/codeql MaD, so inline the lists or keep the dataExtensions wiring in the pack.

    Before opening an upstream pull request

    • Inline the model lists in QL or wire dataExtensions in both the src and test packs
    • Follow CryptImportKey and CryptGetUserKey handles, or narrow the RSA query description
    • Treat MD5/SHA-1 as audit grade, or exclude HMAC and non-security uses
    • Show a true positive on a real project for each query (Community Packs rule)
    • Publish WeakPrng separately as a low precision audit query, or drop it

    Split note. WinCryptWeakAlgorithm medium, WinCryptRsaWithoutOaep medium (narrow), WeakPrng low (audit). All three belong in Community Packs; WeakPrng is the weakest and could be dropped.

    Change from the initial guess. When this issue was opened the coarse destination guess was github/codeql. Reading the actual pull request changed it to Community Packs.

    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-327CWE-328CWE-338CWE-780data-extension-createenhancementprecision:lowseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions