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-022 --project .About This Rule
Understanding the vulnerability and how it is detected
Audit rule that flags all calls to `ec.generate_private_key()` in the `cryptography` library to prompt review of the curve argument. Unlike SEC-020 and SEC-021, this is not a precise detection rule — it matches `CryptoEC.method("generate_private_key")` without filtering on the curve type, because the analysis engine cannot currently inspect the curve object passed as an argument to distinguish approved curves from deprecated ones. The intent is to surface all EC key generation for mandatory human review. Not all curves are equally secure. SECP192R1 (NIST P-192) provides only 96-bit security and is deprecated by NIST SP 800-131A. SECP224R1 (112-bit security) is also deprecated for use after 2030. By contrast, SECP256R1 (128-bit), SECP384R1 (192-bit), and SECP521R1 (260-bit) are all NIST-approved. This rule generates expected false positives for code using approved curves — treat findings as a mandatory audit checkpoint rather than confirmed vulnerabilities.
How to Fix
Recommended remediation steps
- 1Use SECP256R1 (NIST P-256) as the baseline for new EC keys — it is universally supported and provides 128-bit security.
- 2Use SECP384R1 or SECP521R1 for high-value keys or applications requiring compliance with NSA CNSA 2.0.
- 3Never use SECP192R1 or SECP224R1 — both are deprecated by NIST SP 800-131A.
- 4For new applications, consider X25519 for key agreement and Ed25519 for signatures — both are modern audited curves with no parameter-based weaknesses.
- 5Document the curve selection rationale in your security design document for each EC key generation call site.
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 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 EC Key Generation Audit (cryptography lib)
New feature
Get these findings posted directly on your GitHub pull requests
The EC Key Generation Audit (cryptography lib) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.