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-012 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects usage of MD5 via the PyCryptodome or PyCrypto library's `Crypto.Hash.MD5.new()` or `Cryptodome.Hash.MD5.new()` constructor. MD5 produces a 128-bit digest and has been considered cryptographically broken since 2004 (Wang et al., chosen-prefix collision attacks). In 2008 the Flame malware exploited MD5 weaknesses in a Windows Update certificate to execute arbitrary code on patched systems.
PyCryptodome is commonly used in Python projects for cryptographic operations and is the maintained successor to the original PyCrypto library. Both `Crypto.Hash.MD5` (PyCryptodome in drop-in compatibility mode) and `Cryptodome.Hash.MD5` (PyCryptodome standalone) are covered by this rule.
MD5 must not be used for digital signatures, data integrity verification, password hashing, or HMAC-based authentication. It remains acceptable for non-security checksums such as cache keys, file deduplication identifiers, or content-addressable storage where an attacker producing a collision confers no security benefit.
Security Implications
Potential attack scenarios if this vulnerability is exploited
How to Fix
Recommended remediation steps
- 1Replace Crypto.Hash.MD5.new() with Crypto.Hash.SHA256.new() for all integrity and authentication use cases.
- 2For password hashing, do not use any raw hash function including SHA-256 — use Argon2 (argon2-cffi), bcrypt, or scrypt which are designed to be slow and memory-intensive.
- 3For message authentication, use Crypto.Hash.HMAC with SHA-256 as the digest module instead of bare MD5.
- 4MD5 may remain in non-security contexts (cache keys, deduplication) where collision resistance carries no security consequence — add an explicit comment documenting this intent.
- 5When migrating stored MD5 checksums (e.g., in a database), rehash with SHA-256 on next verified access and deprecate the MD5 code path with a sunset date.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
Matches any call to `PyCryptoHashMD5.method("new")` where `PyCryptoHashMD5` is a QueryType resolving fully-qualified names `Crypto.Hash.MD5` and `Cryptodome.Hash.MD5`. This covers both the PyCryptodome drop-in compatibility namespace (`Crypto.*`) and the standalone namespace (`Cryptodome.*`). The rule fires on `.new()` constructor invocation, which is the standard PyCryptodome pattern for instantiating hash objects.
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 (PyCryptodome)
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure MD5 Hash (PyCryptodome) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.