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-020 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects RSA key generation using `rsa.generate_private_key()` from the `cryptography` library where the `key_size` argument is less than 2048 bits. This rule uses a `.where("key_size", lt(2048))` predicate so it fires only on provably undersized keys and does not flag 2048-bit or larger keys. RSA keys shorter than 2048 bits are vulnerable to integer factorization: a 1024-bit RSA key can be factored with sustained effort and widely available cloud compute. NIST formally deprecated 1024-bit RSA in 2013 (SP 800-131A) and requires 2048-bit minimum through 2030, after which 3072-bit keys will be the minimum for new systems. Use 3072-bit or 4096-bit RSA for new applications, or prefer ECDSA with SECP256R1/SECP384R1 which provides equivalent security with significantly shorter keys.
How to Fix
Recommended remediation steps
- 1Use RSA key_size=3072 or key_size=4096 for any new application.
- 2NIST SP 800-57 equates 2048-bit RSA to only 112-bit security; 3072-bit RSA provides 128-bit security.
- 3Prefer ECDSA (SECP256R1 or SECP384R1) over RSA for new systems — same security level with shorter keys and faster operations.
- 4Audit existing certificates and key material to identify keys below 2048 bits and schedule rotation.
- 5Set a key expiry policy so that any 2048-bit keys currently in use are rotated before NIST's 2030 deprecation deadline.
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 RSA Key Size (cryptography lib)
New feature
Get these findings posted directly on your GitHub pull requests
The Insufficient RSA Key Size (cryptography lib) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.