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-011 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects usage of SHA-1 via the `cryptography` library's hazmat primitives interface (`hashes.SHA1()`). SHA-1 produces a 160-bit digest and was formally broken in 2017 when the SHAttered attack (Stevens et al., CWI/Google) produced the first known SHA-1 collision using approximately 6,500 CPU-years of computation. Chosen-prefix collisions, which are more dangerous in practice, were demonstrated in 2020 at lower cost.
NIST deprecated SHA-1 for digital signatures in SP 800-131A and disallowed its use in federal agencies after 2013. Browser vendors removed SHA-1 certificate trust in 2017. Major Certificate Authorities have been prohibited from issuing SHA-1-signed certificates since 2016.
SHA-1 must not be used for digital signatures, TLS certificates, code signing, or any protocol where collision resistance is a security property. It retains limited legacy compatibility use in non-security contexts such as Git object addressing, though even there SHA-256 migration is underway. This rule targets the hazmat layer of the `cryptography` library, indicating intentional low-level cryptographic use.
Security Implications
Potential attack scenarios if this vulnerability is exploited
How to Fix
Recommended remediation steps
- 1Replace hashes.SHA1() with hashes.SHA256() for general-purpose hashing and integrity verification.
- 2Use hashes.SHA3_256() or hashes.SHA3_512() when stronger collision resistance is required or as a hedge against future weaknesses in SHA-2.
- 3For password hashing, do not use SHA-1 or any raw hash — use Argon2 (argon2-cffi), bcrypt, or scrypt.
- 4For HMAC-based message authentication, use HMAC with SHA-256 (cryptography.hazmat.primitives.hmac.HMAC with hashes.SHA256()).
- 5When SHA-1 appears in a legacy protocol or file format you do not control, isolate the usage and layer a SHA-256 HMAC or signature over the output as a compensating control.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
Matches any call to `CryptoHashes.method("SHA1")` where `CryptoHashes` is a QueryType resolving fully-qualified names under `cryptography.hazmat.primitives.hashes`. This catches `hashes.SHA1()` regardless of import aliasing. The rule fires on instantiation of the SHA1 hash object within the cryptography library's hazmat primitives layer, not on the PyCryptodome SHA1 equivalent (see PYTHON-CRYPTO-SEC-015 for that).
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
RC4 (ARC4) Cipher Usage via cryptography Library
Detects use of the RC4 stream cipher through the cryptography library's ARC4 algorithm, which has known keystream biases and is prohibited by RFC 7465.
RC4 (ARC4) Cipher Usage via PyCryptodome
Detects use of the RC4 stream cipher through PyCryptodome's ARC4 module, which has known keystream biases and is prohibited by RFC 7465.
Blowfish Cipher Usage via cryptography Library
Detects use of the Blowfish cipher through the cryptography library, which has a 64-bit block size making it vulnerable to Sweet32 birthday attacks after approximately 32GB of data.
Frequently Asked Questions
Common questions about Insecure SHA1 Hash (cryptography)
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure SHA1 Hash (cryptography) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.