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-014 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects usage of MD2 via PyCryptodome's `Crypto.Hash.MD2.new()` or `Cryptodome.Hash.MD2.new()` constructor. MD2 was designed by Ron Rivest in 1989 and is the oldest of the MD family. It was deprecated by the IETF in RFC 6149 in 2011 with the explicit recommendation that it "SHOULD NOT be used."
MD2 produces a 128-bit digest but uses an 8-bit oriented design with a permutation table that makes it extremely slow compared to all modern alternatives. Muller (2004) demonstrated a preimage attack reducing work to 2^104, well below MD2's intended 2^128 security level. Knudsen and Mathiassen published further weaknesses. The algorithm has no collision resistance properties appropriate for modern use.
Unlike MD5 which sees legitimate non-security use as a fast checksum, MD2 is so slow and so thoroughly analyzed for weaknesses that there is no context in which it is preferable to a modern algorithm. Any appearance of MD2 in a codebase indicates either extreme legacy code (e.g., old X.509 certificate parsing from early-1990s PKI) or a mistake.
This rule is rated HIGH severity because MD2 combines known cryptographic weaknesses with zero remaining legitimate use cases and no performance rationale for its selection.
Security Implications
Potential attack scenarios if this vulnerability is exploited
How to Fix
Recommended remediation steps
- 1Replace Crypto.Hash.MD2.new() with Crypto.Hash.SHA256.new() — SHA-256 is faster, stronger, and universally supported.
- 2For password hashing, use Argon2id (argon2-cffi), bcrypt, or scrypt rather than any raw hash function including SHA-256.
- 3If the code is parsing legacy X.509 certificates that use MD2withRSA signatures, use a modern TLS/PKI library that correctly rejects MD2-signed certificates rather than reimplementing the verification.
- 4Audit all call sites thoroughly — any code using MD2 is likely very old and may contain other cryptographic weaknesses worth reviewing.
- 5Use Crypto.Hash.HMAC with SHA-256 as the digest module for message authentication codes rather than any MD-family algorithm.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
Matches any call to `PyCryptoHashMD2.method("new")` where `PyCryptoHashMD2` is a QueryType resolving fully-qualified names `Crypto.Hash.MD2` and `Cryptodome.Hash.MD2`. This covers both the PyCryptodome drop-in compatibility namespace (`Crypto.*`) and the standalone namespace (`Cryptodome.*`). The rule fires on `.new()` constructor invocation. Any detection of this rule in production code warrants immediate review — legitimate current uses of MD2.new() are virtually nonexistent outside of legacy protocol parsers for early-1990s X.509 formats.
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 MD2 Hash (PyCryptodome)
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure MD2 Hash (PyCryptodome) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.