Overview
This vulnerability occurs when an application uses a password hashing algorithm that is too fast, even if it’s cryptographically strong for other purposes (like SHA-256 or SHA-512). Fast hashes allow attackers to perform rapid offline brute-force or dictionary attacks if they obtain a database of password hashes. Modern password hashing requires algorithms designed to be computationally expensive (slow) and memory-hard to significantly hinder attackers.Business Impact
If an attacker steals password hashes stored using fast algorithms, they can quickly crack many of them, especially common or weak passwords. This leads to widespread account compromise, allowing attackers to impersonate users, steal sensitive data linked to those accounts, and potentially pivot to other systems. 🔑💥Reference Details
CWE ID: CWE-916
OWASP Top 10 (2021): A02:2021 - Cryptographic Failures
Severity: High
Framework-Specific Analysis and Remediation
Secure password hashing relies on algorithms like bcrypt, scrypt, Argon2, or PBKDF2. The vulnerability arises when developers manually implement hashing using fast algorithms like SHA-256 directly, often combined with a salt but without sufficient iterations or work factor. Framework defaults are usually secure, but custom implementations or legacy code are common sources of this weakness.- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
Django defaults to PBKDF2_SHA256, which is acceptable but slower is better. Usinghashlib.sha256 directly is the vulnerability.Vulnerable Scenario 1: Direct SHA-256 Hashing
A custom user model useshashlib.sha256 directly with just a salt.Vulnerable Scenario 2: Using PBKDF2 with Low Iterations
Usinghashlib.pbkdf2_hmac but setting the iteration count too low.Mitigation and Best Practices
Use Django’s built-in password management (user.set_password(raw_password), user.check_password(raw_password)). Configure PASSWORD_HASHERS in settings.py to prioritize Argon2PasswordHasher or BCryptSHA256PasswordHasher. Ensure PBKDF2 iterations are high if used.Secure Code Example
Testing Strategy
Inspect password hashes in the database. They should start withargon2$, bcrypt$, or pbkdf2_sha256$. Manually check the iteration count if using PBKDF2 (it’s part of the stored hash string). Ensure no code uses hashlib.sha256 etc. directly for passwords.
