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-034 --project .About This Rule
Understanding the vulnerability and how it is detected
Using MD5 to hash passwords is a critical vulnerability. MD5 has two fatal properties for password hashing: it is cryptographically broken (collision attacks exist) and it is extremely fast (modern GPUs can compute billions of MD5 hashes per second).
Password hashing requires a slow, memory-hard function specifically designed to resist brute-force attacks. bcrypt, scrypt, and Argon2 are purpose-built for this: they are deliberately slow, use significant memory, and have configurable work factors that can be increased as hardware improves.
This rule detects patterns where hashlib.md5() is called in proximity to password-related variables, functions, or context, indicating MD5 is being used for credential storage. Even salted MD5 is insufficient — a salted MD5 database can be cracked in hours using GPU clusters.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Trivial Database Cracking After Breach
A leaked database of MD5-hashed passwords can be completely cracked in hours to days using GPU-based tools like hashcat. Modern GPUs compute 50+ billion MD5 hashes per second, making even complex passwords vulnerable to brute force within hours.
Rainbow Table Attacks on Unsalted Passwords
Without a unique per-user salt, common passwords have identical MD5 hashes across all users. Precomputed rainbow tables covering hundreds of millions of common passwords are freely available, enabling instant cracking of any password whose MD5 hash is in the table.
Credential Stuffing Risk
Once cracked from a MD5 hash database, plaintext passwords can be used in credential stuffing attacks against other services where users reuse passwords, amplifying the damage beyond the original breach.
Compliance Violations
Storing passwords with MD5 violates PCI DSS, NIST SP 800-63B, and most data protection regulations that mandate strong, modern password hashing. A breach of MD5-hashed passwords triggers mandatory notification requirements under GDPR and similar laws.
How to Fix
Recommended remediation steps
- 1Replace MD5 password hashing with argon2-cffi (Argon2id algorithm), which is the current OWASP and NIST recommendation for new systems.
- 2If argon2 is not available, use bcrypt with a work factor of at least 12 or hashlib.scrypt() from the Python standard library.
- 3Never use bare MD5, SHA-1, SHA-256, or any general-purpose hash function for password storage, even with a salt.
- 4Implement a migration path for existing MD5 password hashes: rehash with a secure algorithm when users next authenticate.
- 5Ensure each password has a unique random salt (all three recommended libraries handle this automatically).
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects hashlib.md5() calls in contexts that suggest password hashing usage, such as proximity to variables named password, passwd, pwd, credential, or auth, and function names containing these terms. The rule is intentionally broad to catch all patterns where MD5 is applied to credentials.
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 SHA-1 Hash Usage
SHA-1 is cryptographically weak due to practical collision attacks. Use SHA-256 or SHA-3 for security-sensitive hashing.
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.
Frequently Asked Questions
Common questions about MD5 Used for Password Hashing
New feature
Get these findings posted directly on your GitHub pull requests
The MD5 Used for Password Hashing rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.