Overview
This vulnerability occurs when an application uses cryptographic algorithms that are known to be weak, broken, or deprecated. This includes using outdated hashing algorithms like MD5 or SHA1 for password storage, using weak encryption ciphers like DES, or employing cryptographic modes that are susceptible to attacks (like ECB mode for block ciphers).Business Impact
Using broken cryptography provides a false sense of security. 🛡️ Attackers can often break this weak protection easily, leading to the compromise of sensitive data like passwords, PII, or financial information. If password hashes are cracked, attackers gain access to user accounts. If encryption is broken, all encrypted data is exposed.Reference Details
CWE ID: CWE-327
OWASP Top 10 (2021): A02:2021 - Cryptographic Failures
Severity: High
Framework-Specific Analysis and Remediation
Modern frameworks generally default to strong algorithms (e.g., bcrypt/Argon2 for passwords, AES-GCM for encryption). This vulnerability arises when developers:- Explicitly choose a weak algorithm (often for legacy compatibility or misunderstanding).
- Use outdated libraries or configurations.
- Implement crypto manually instead of using framework defaults.
- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
Django defaults to PBKDF2_SHA256 for passwords, which is acceptable but bcrypt or Argon2 are stronger. For encryption, developers might use the olderhashlib for passwords or weak pycryptodome configurations.Vulnerable Scenario 1: Using MD5 for Passwords
A legacy system or custom user model uses MD5 directly.Vulnerable Scenario 2: Weak Encryption Cipher
Usingpycryptodome with DES or ECB mode.Mitigation and Best Practices
Use Django’s default password hashing (django.contrib.auth.hashers). If you need stronger hashing, configure PASSWORD_HASHERS to prioritize bcrypt or Argon2. For encryption, use AES with GCM mode (provides integrity) or CBC mode with a random IV and MAC.Secure Code Example
Testing Strategy
Check thepassword field in your user database. Hashes should start with prefixes like argon2$, bcrypt$, or pbkdf2_sha256$, not just raw hex. For encryption, write unit tests ensuring the correct algorithm (AES) and mode (GCM/CBC) are used.
