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-023 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects RSA key generation using `RSA.generate(bits)` from PyCryptodome where the first positional argument (key size in bits) is less than 3072. This rule uses a `.where(0, lt(3072))` predicate targeting position 0 of the call — it fires only on provably undersized keys and does not flag 3072-bit or larger keys. The 3072-bit threshold is deliberately stricter than the SEC-020 `cryptography` library rule (which uses 2048 as the floor). PyCryptodome's own documentation recommends 3072-bit keys for new applications to ensure adequate security beyond 2030. NIST SP 800-57 equates 3072-bit RSA to 128-bit symmetric security. A 2048-bit RSA key provides only 112-bit security and is scheduled for deprecation by NIST after 2030. RSA keys shorter than 3072 bits are vulnerable to the General Number Field Sieve factorization algorithm given sufficient compute. For new systems, consider ECDSA with SECP256R1 or SECP384R1 which provides equivalent or stronger security with significantly shorter keys.
How to Fix
Recommended remediation steps
- 1Use RSA.generate(3072) as the minimum for PyCryptodome RSA key generation.
- 2Use RSA.generate(4096) for long-lived keys such as CA certificates or signing keys.
- 3Consider replacing RSA with ECC — ECC.generate(curve='P-256') provides equivalent security to RSA-3072 with a 256-bit key.
- 4Note that this rule is stricter than SEC-020 (cryptography lib) which uses 2048 as the floor; aligning on 3072 ensures systems will remain compliant beyond 2030.
- 5Audit all RSA key material in your infrastructure and schedule rotation of any keys below 3072 bits on a risk-based timeline.
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 RSA Key Size (cryptography lib)
RSA key size is less than 2048 bits. NIST minimum is 2048 bits; 3072+ recommended for new systems.
Insufficient DSA Key Size (cryptography lib)
DSA key size is less than 2048 bits. NIST SP 800-131A requires 2048-bit minimum.
Insufficient DSA Key Size (PyCryptodome)
DSA key size is less than 2048 bits in PyCryptodome. Use DSA.generate(2048) or higher.
Frequently Asked Questions
Common questions about Insufficient RSA Key Size (PyCryptodome)
New feature
Get these findings posted directly on your GitHub pull requests
The Insufficient RSA Key Size (PyCryptodome) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.