Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-CRYPTO-SEC-024 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects DSA key generation using `DSA.generate(bits)` from PyCryptodome where the first positional argument (key size in bits) is less than 2048. This rule uses a `.where(0, lt(2048))` predicate targeting position 0 — it fires only on provably undersized keys and does not flag 2048-bit or larger keys. DSA with small keys is vulnerable to discrete logarithm attacks. A 1024-bit DSA key can have its private key recovered through index calculus methods, enabling an attacker to forge arbitrary signatures. NIST SP 800-131A formally deprecated 1024-bit DSA in 2013 and requires 2048-bit minimum. Beyond the key size risk, DSA signing requires a cryptographically random per-signature nonce (k): a reused nonce across two signatures algebraically exposes the private key regardless of key size, as demonstrated in the 2010 Sony PlayStation 3 master key extraction. For new applications, prefer ECDSA (ECC.generate(curve='P-256')) or avoid DSA entirely.
How to Fix
Recommended remediation steps
- 1Use DSA.generate(2048) as the absolute minimum; use DSA.generate(3072) for systems requiring protection beyond 2030.
- 2Consider replacing DSA with ECC (curve='P-256' or 'P-384') for new applications — smaller keys, faster operations, and immune to nonce-reuse catastrophe when using EdDSA.
- 3If DSA must be used, ensure the per-signature nonce (k) is generated from a CSPRNG; never reuse a nonce across two signatures with the same key.
- 4Audit all DSA key material and schedule rotation of any keys below 2048 bits.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Insufficient DSA Key Size (cryptography lib)
DSA key size is less than 2048 bits. NIST SP 800-131A requires 2048-bit minimum.
EC Key Generation Audit (cryptography lib)
Audit all EC key generation calls — verify the curve is SECP256R1, SECP384R1, or stronger. Weak curves like SECP192R1 must not be used.
Insufficient RSA Key Size (PyCryptodome)
RSA key size is less than 3072 bits in PyCryptodome. Use RSA.generate(3072) or higher.
Frequently Asked Questions
Common questions about Insufficient DSA Key Size (PyCryptodome)
New feature
Get these findings posted directly on your GitHub pull requests
The Insufficient DSA Key Size (PyCryptodome) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.