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-LANG-SEC-031 --project .About This Rule
Understanding the vulnerability and how it is detected
SHA-1 (Secure Hash Algorithm 1) produces a 160-bit digest and has been deprecated for cryptographic use since 2011. In 2017, the SHAttered attack demonstrated a practical SHA-1 collision, and chosen-prefix collision attacks became feasible in 2019, enabling forgery of X.509 certificates, PGP keys, and other structures that use SHA-1 signatures.
SHA-1 should not be used for digital signatures, certificate fingerprinting, HMAC in new protocols, code signing, password hashing, or any context where collision resistance is a security requirement. NIST formally deprecated SHA-1 for all security applications in 2022.
SHA-1 retains some non-security uses: it remains acceptable for non-adversarial integrity checks, content-addressed storage where the threat model does not include adversarial input, and HMAC-SHA1 in legacy protocol compatibility (where cryptographic analysis shows HMAC construction still provides MAC security despite the hash's weaknesses).
Security Implications
Potential attack scenarios if this vulnerability is exploited
Chosen-Prefix Collision Attacks
Chosen-prefix collisions allow an attacker to craft two documents with identical SHA-1 hashes where each document starts with attacker-chosen content. This has been used to forge X.509 certificates and create malicious files that match expected checksums. The attack cost is within reach of well-funded attackers.
Certificate Forgery
X.509 certificates using SHA-1 signatures can be forged through collision attacks. Major browser vendors and CA/Browser Forum deprecated SHA-1 certificates in 2016-2017. Applications still accepting SHA-1 certificate fingerprints are vulnerable to certificate impersonation attacks.
Code Signing Weakness
Software signed with SHA-1 can potentially be replaced by malicious code with a crafted collision that produces the same SHA-1 hash, undermining software supply chain integrity.
PGP Key Forgery
PGP/GPG uses SHA-1 for key fingerprints in older key formats. SHA-1 collision attacks have been demonstrated against PGP key certification signatures, enabling key impersonation in some configurations.
How to Fix
Recommended remediation steps
- 1Replace hashlib.sha1() with hashlib.sha256() or hashlib.sha3_256() for all security-sensitive hashing operations.
- 2Update certificate fingerprint verification to use SHA-256 fingerprints.
- 3Migrate code signing pipelines from SHA-1 to SHA-256 or stronger algorithms.
- 4For HMAC in new code, use HMAC-SHA-256; HMAC-SHA1 may be retained only for legacy protocol compatibility where migration is not feasible.
- 5Audit all SHA-1 usages and document whether each is security-sensitive or acceptable for non-adversarial use.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to hashlib.sha1() in Python source code. All call sites are flagged for review. Security-sensitive uses require migration to SHA-256 or stronger. Non-security uses and HMAC-SHA1 for legacy compatibility may be documented and suppressed.
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
Insecure MD5 Hash Usage
MD5 is cryptographically broken and unsuitable for security-sensitive purposes. Use SHA-256 or SHA-3 instead.
Insecure Hash via hashlib.new()
hashlib.new() with an insecure algorithm name (MD5, SHA1, SHA-224) creates a cryptographically weak hash. Use SHA-256 or SHA-3.
SHA-224 or SHA3-224 Weak Hash Usage
SHA-224 and SHA3-224 provide only 112-bit collision resistance, which is below the 128-bit minimum recommended by NIST for new applications.
Frequently Asked Questions
Common questions about Insecure SHA-1 Hash Usage
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure SHA-1 Hash Usage rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.