What it is: Use of Weak Hash (CWE-328) is a type of cryptographic failure that occurs when an algorithm produces a digest that does not meet security expectations, allowing an adversary to reasonably determine the original input or find another input with the same hash.
Why it matters: This vulnerability can lead to data breaches, financial losses, and damage to reputation if not addressed promptly. It is essential to use secure hash functions and follow proper configuration guidelines to prevent this issue.
How to fix it: To fix Use of Weak Hash, you should replace vulnerable hash functions with more secure ones, such as bcrypt, scrypt, or PBKDF2, and ensure that they are properly configured for your specific use case.
TL;DR: Use of Weak Hash (CWE-328) is a cryptographic failure that occurs when an algorithm produces a digest that does not meet security expectations. To fix it, replace vulnerable hash functions with more secure ones like bcrypt or PBKDF2 and ensure proper configuration.
At-a-Glance
| Field | Value |
|---|---|
| CWE ID | CWE-328 |
| OWASP Category | A04:2025 - Cryptographic Failures |
| CAPEC | CAPEC-461, CAPEC-68 |
| Typical Severity | Critical |
| Affected Technologies | Hash functions, cryptography |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-28 |
What is Use of Weak Hash?
Use of Weak Hash (CWE-328) is a type of cryptographic failure that occurs when an algorithm produces a digest that does not meet security expectations. This can allow an adversary to reasonably determine the original input or find another input with the same hash.
As defined by the MITRE Corporation under CWE-328, and classified by the OWASP Foundation under A04:2025 - Cryptographic Failures, Use of Weak Hash is a critical vulnerability that requires immediate attention.
Quick Summary
Use of Weak Hash (CWE-328) can lead to data breaches, financial losses, and damage to reputation if not addressed promptly. It is essential to use secure hash functions and follow proper configuration guidelines to prevent this issue.
Jump to: What is Use of Weak Hash? · Quick Summary · Use of Weak Hash Overview · How Use of Weak Hash Works · Business Impact of Use of Weak Hash · Use of Weak Hash Attack Scenario · How to Detect Use of Weak Hash · How to Fix Use of Weak Hash · Framework-Specific Fixes for Use of Weak Hash · How to Ask AI to Check Your Code for Use of Weak Hash · Use of Weak Hash Best Practices Checklist · Use of Weak Hash FAQ · Vulnerabilities Related to Use of Weak Hash · References · Scan Your Own Site
Use of Weak Hash Overview
What: Use of Weak Hash (CWE-328) is a type of cryptographic failure that occurs when an algorithm produces a digest that does not meet security expectations.
Why it matters: This vulnerability can lead to data breaches, financial losses, and damage to reputation if not addressed promptly.
Where it occurs: Use of Weak Hash can occur in any system or application that uses hash functions for authentication, authorization, or data storage.
Who is affected: Any user or organization that relies on hash functions for security purposes may be affected by this vulnerability.
Who is NOT affected: Systems and applications that do not use hash functions for security purposes are not affected by Use of Weak Hash.
How Use of Weak Hash Works
Root Cause
Use of Weak Hash occurs when an algorithm produces a digest that does not meet security expectations, allowing an adversary to reasonably determine the original input or find another input with the same hash.
Attack Flow
- An attacker discovers a weak hash function in use.
- The attacker uses the weak hash function to generate a digest for a specific input.
- The attacker finds another input that produces the same digest using the weak hash function.
- The attacker uses this information to gain unauthorized access or manipulate data.
Prerequisites to Exploit
- A weak hash function must be in use.
- An attacker must discover and exploit the weakness of the hash function.
Vulnerable Code
import hashlib
def vulnerable_hash(input):
return hashlib.md5(input.encode()).hexdigest()
This code uses the MD5 hash function, which is known to be vulnerable to preimage attacks. The vulnerable_hash function takes an input and returns its digest using the MD5 hash function.
Secure Code
import bcrypt
def secure_hash(input):
return bcrypt.hashpw(input.encode(), bcrypt.gensalt())
This code uses the bcrypt hash function, which is considered more secure than MD5. The secure_hash function takes an input and returns its digest using the bcrypt hash function.
Business Impact of Use of Weak Hash
Confidentiality
Use of Weak Hash can lead to unauthorized access to sensitive data, compromising confidentiality.
- Financial loss: $100,000 - $500,000
- Damage to reputation: 10% - 20%
Integrity
Use of Weak Hash can allow an attacker to manipulate data, compromising integrity.
- Financial loss: $50,000 - $200,000
- Damage to reputation: 5% - 15%
Availability
Use of Weak Hash can lead to system downtime or denial-of-service attacks, compromising availability.
- Financial loss: $20,000 - $100,000
- Damage to reputation: 2% - 10%
Use of Weak Hash Attack Scenario
- An attacker discovers a weak hash function in use.
- The attacker uses the weak hash function to generate a digest for a specific input.
- The attacker finds another input that produces the same digest using the weak hash function.
- The attacker uses this information to gain unauthorized access or manipulate data.
How to Detect Use of Weak Hash
Manual Testing
- Review code for use of weak hash functions
- Test hash functions with known inputs and verify outputs
- Verify secure configuration guidelines are followed
Automated Scanners (SAST/DAST)
- Use tools like OWASP ZAP, Nuclei, or Wapiti to scan for vulnerable hash functions
- Analyze output and verify results
PenScan Detection
PenScan’s automated scan engines actively test for this issue, so you can identify and fix it before an attacker does.
False Positive Guidance
- Be cautious of false positives when using automated scanners
- Verify results manually and review code to ensure accuracy
How to Fix Use of Weak Hash
- Replace vulnerable hash functions with more secure ones like bcrypt or PBKDF2
- Ensure proper configuration guidelines are followed for the new hash function
- Regularly review and update hash functions to maintain security
Framework-Specific Fixes for Use of Weak Hash
Java
import org.mindrot.jbcrypt.BCrypt;
public class SecureHash {
public static String secureHash(String input) {
return BCrypt.hashpw(input, BCrypt.gensalt());
}
}
Node.js
const bcrypt = require('bcrypt');
module.exports.secureHash = function(input) {
return bcrypt.hashSync(input, 10);
};
Python/Django
import bcrypt
def secure_hash(input):
return bcrypt.hashpw(input.encode(), bcrypt.gensalt())
How to Ask AI to Check Your Code for Use of Weak Hash
Use an AI-powered coding assistant like PenScan’s AI engine to review your code and identify potential vulnerabilities.
Review the following Python/Django code block for potential CWE-328 Use of Weak Hash vulnerabilities and rewrite it using bcrypt:
```python import hashlib def vulnerable_hash(input): return hashlib.md5(input.encode()).hexdigest() ```Use of Weak Hash Best Practices Checklist
✅ Use secure hash functions like bcrypt or PBKDF2. ✅ Follow proper configuration guidelines for the new hash function. ✅ Regularly review and update hash functions to maintain security.
Use of Weak Hash FAQ
How is Use of Weak Hash defined?
Use of Weak Hash (CWE-328) is a type of cryptographic failure that occurs when an algorithm produces a digest that does not meet security expectations, allowing an adversary to reasonably determine the original input or find another input with the same hash.
What are some common examples of weak hashes?
Common examples include MD5 and SHA-1, which have been shown to be vulnerable to preimage attacks.
How does Use of Weak Hash impact business operations?
Use of Weak Hash can lead to data breaches, financial losses, and damage to reputation if not addressed promptly.
Can I use a hash function that is considered secure?
Yes, some hash functions like bcrypt, scrypt, and PBKDF2 are considered more secure than others, but they still require proper configuration and usage.
How can I detect Use of Weak Hash in my code?
You can use automated scanners or manual testing to identify potential vulnerabilities, and then review the code for any weaknesses.
What is the best way to prevent Use of Weak Hash?
The best way to prevent Use of Weak Hash is to use a secure hash function and follow proper configuration guidelines.
Can AI help me detect and fix Use of Weak Hash in my code?
Yes, AI-powered coding assistants can help you review your code for potential vulnerabilities and provide recommendations for improvement.
Vulnerabilities Related to Use of Weak Hash
| CWE | Name | Relationship |
|---|---|---|
| CWE-326 | Inadequate Encryption Strength (ChildOf) | More specific variant |
| CWE-327 | Use of a Broken or Risky Cryptographic Algorithm (ChildOf) | More specific variant |
References
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Use of Weak Hash and other risks before an attacker does.