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-010 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects usage of MD5 via the `cryptography` library's hazmat primitives interface (`hashes.MD5()`). MD5 produces a 128-bit digest and has been considered cryptographically broken since 2004 when Wang et al. demonstrated practical chosen-prefix collision attacks. By 2008, rogue CA certificates were forged using MD5 collisions in under hours of computation. Today, MD5 collisions can be produced in seconds on commodity hardware.
MD5 must not be used for digital signatures, certificate validation, HMAC-based authentication, or data integrity verification in security contexts. It remains acceptable for non-security purposes such as cache keys, file deduplication, or content-addressable storage where collision resistance is not a security requirement.
This rule specifically targets `cryptography.hazmat.primitives.hashes.MD5` instantiation, which is the hazmat (Hazardous Materials) layer indicating the caller is expected to understand the risks — yet MD5 is still dangerous regardless of the API used.
Security Implications
Potential attack scenarios if this vulnerability is exploited
How to Fix
Recommended remediation steps
- 1Replace hashes.MD5() with hashes.SHA256() or hashes.SHA3_256() for all integrity and signing use cases.
- 2For password hashing, do not use any raw hash function — use a memory-hard KDF such as Argon2 (argon2-cffi), bcrypt, or scrypt instead.
- 3For HMAC authentication, use HMAC with SHA-256 or SHA-3 (cryptography.hazmat.primitives.hmac with hashes.SHA256()).
- 4MD5 may remain in place for purely non-security uses (cache keys, file deduplication) where collision resistance carries no security consequence — document this explicitly.
- 5When migrating existing MD5-hashed data (e.g., stored checksums), re-hash with SHA-256 on first verified access and deprecate the MD5 path.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
Matches any call to `CryptoHashes.method("MD5")` where `CryptoHashes` is a QueryType resolving fully-qualified names under `cryptography.hazmat.primitives.hashes`. This catches `hashes.MD5()` regardless of how the `hashes` module is imported or aliased. The rule fires on instantiation of the MD5 hash object, not on specific method calls made on the resulting digest object.
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 MD5 Hash (cryptography)
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure MD5 Hash (cryptography) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.