What it is: Predictable Exact Value from Previous Values (CWE-342) is a vulnerability where an exact value or random number can be precisely predicted by observing previous values.
Why it matters: This weakness undermines cryptographic security and privacy, allowing attackers to compromise encryption keys and session identifiers.
How to fix it: Increase the entropy used to seed a PRNG or use FIPS 140-2 approved random number generators.
TL;DR: Predictable Exact Value from Previous Values (CWE-342) is a vulnerability where an exact value or random number can be precisely predicted by observing previous values, undermining cryptographic security and privacy. Increase the entropy used to seed a PRNG or use FIPS 140-2 approved random number generators.
| Field | Value |
|---|---|
| CWE ID | CWE-342 |
| OWASP Category | A04:2025 - Cryptographic Failures |
| CAPEC | None known |
| Typical Severity | High |
| Affected Technologies | PRNGs, cryptographic libraries |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-29 |
What is Predictable Exact Value from Previous Values?
Predictable Exact Value from Previous Values (CWE-342) is a type of vulnerability where an exact value or random number can be precisely predicted by observing previous values. As defined by the MITRE Corporation under CWE-342, and classified by the OWASP Foundation under A04:2025 - Cryptographic Failures.
Quick Summary
Predictable Exact Value from Previous Values is a critical security flaw that undermines cryptographic systems by enabling attackers to predict future random numbers based on past values. This can lead to compromised encryption keys, session identifiers, and other sensitive data. The vulnerability occurs in applications using poor quality pseudo-random number generators (PRNGs) with insufficient entropy.
Jump to: Quick Summary · Predictable Exact Value from Previous Values Overview · How Predictable Exact Value from Previous Values Works · Business Impact of Predictable Exact Value from Previous Values · Predictable Exact Value from Previous Values Attack Scenario · How to Detect Predictable Exact Value from Previous Values · How to Fix Predictable Exact Value from Previous Values · Framework-Specific Fixes for Predictable Exact Value from Previous Values · How to Ask AI to Check Your Code for Predictable Exact Value from Previous Values · Predictable Exact Value from Previous Values Best Practices Checklist · Predictable Exact Value from Previous Values FAQ · Vulnerabilities Related to Predictable Exact Value from Previous Values · References · Scan Your Own Site
Predictable Exact Value from Previous Values Overview
What: A vulnerability where an exact value or random number can be precisely predicted by observing previous values.
Why it matters: Compromises cryptographic security and privacy, enabling attackers to predict future random numbers, weaken encryption keys, and gain unauthorized access.
Where it occurs: In applications using poor quality pseudo-random number generators (PRNGs) with insufficient entropy.
Who is affected: Applications relying on weak PRNGs for generating random values used in cryptographic operations.
Who is NOT affected: Systems already using high-quality random number generators conforming to FIPS 140-2 standards, or those that periodically reseed their PRNGs with high-quality sources of entropy.
How Predictable Exact Value from Previous Values Works
Root Cause
The root cause lies in the use of pseudo-random number generators (PRNGs) that produce predictable sequences when seeded with insufficient entropy. Observing previous values allows attackers to predict future outputs, compromising cryptographic security.
Attack Flow
- Attacker observes a sequence of generated random numbers.
- Analyzes the pattern and predicts subsequent values.
- Uses predicted values to compromise encryption keys or session identifiers.
Prerequisites to Exploit
- The application must use a PRNG with insufficient entropy.
- The attacker needs access to observe previous random number sequences.
Vulnerable Code
import java.security.SecureRandom;
public class Example {
public static void main(String[] args) {
SecureRandom prng = new SecureRandom();
// Weak seeding mechanism
prng.setSeed(new byte[]{0x01, 0x02, 0x03});
int nextValue = prng.nextInt();
System.out.println("Next value: " + nextValue);
}
}
Secure Code
import java.security.SecureRandom;
public class Example {
public static void main(String[] args) {
SecureRandom prng = new SecureRandom();
// Strong seeding mechanism using high-quality entropy source
prng.setSeed(SecureRandom.getInstanceStrong().generateSeed(16));
int nextValue = prng.nextInt();
System.out.println("Next value: " + nextValue);
}
}
Business Impact of Predictable Exact Value from Previous Values
Confidentiality: Compromises encryption keys and session identifiers, leading to unauthorized access.
Integrity: Enables attackers to forge or tamper with sensitive data.
Availability: Can disrupt services by causing denial-of-service conditions through resource exhaustion attacks leveraging predictable values.
Predictable Exact Value from Previous Values Attack Scenario
- Attacker monitors a sequence of random numbers generated by an application.
- Analyzes the pattern and predicts future values.
- Uses predicted values to compromise encryption keys or session identifiers, gaining unauthorized access to sensitive data.
How to Detect Predictable Exact Value from Previous Values
Manual Testing
- Review code for PRNG initialization with weak seeding mechanisms.
- Check if high-quality entropy sources are used to seed PRNGs.
- Analyze patterns in generated random numbers to detect predictability.
Automated Scanners (SAST / DAST)
Static analysis can identify poor quality PRNG implementations, while dynamic testing is needed to observe actual sequences and patterns.
PenScan Detection
PenScan’s scanner engines such as ZAP, Nuclei, Wapiti, Nikto, SSLyze, Dalfox, and Nmap may detect this vulnerability by analyzing PRNG usage and entropy sources.
False Positive Guidance
A real finding will show predictable patterns in generated random numbers. A false positive might appear when a strong PRNG is used but the sequence appears non-random due to lack of observable context.
How to Fix Predictable Exact Value from Previous Values
- Increase the entropy used to seed a PRNG.
- Use products or modules that conform to FIPS 140-2 standards.
- Ensure PRNGs periodically re-seed themselves using high-quality sources, without over-reseeding.
Framework-Specific Fixes for Predictable Exact Value from Previous Values
Java
import java.security.SecureRandom;
public class Example {
public static void main(String[] args) {
SecureRandom prng = new SecureRandom();
// Strong seeding mechanism using high-quality entropy source
prng.setSeed(SecureRandom.getInstanceStrong().generateSeed(16));
int nextValue = prng.nextInt();
System.out.println("Next value: " + nextValue);
}
}
How to Ask AI to Check Your Code for Predictable Exact Value from Previous Values
Review the following Java code block for potential CWE-342 Predictable Exact Value from Previous Values vulnerabilities and rewrite it using SecureRandom class: [paste code here]
Predictable Exact Value from Previous Values Best Practices Checklist
✅ Increase entropy used to seed a PRNG. ✅ Use products or modules that conform to FIPS 140-2 standards. ✅ Ensure PRNGs periodically re-seed themselves using high-quality sources.
Predictable Exact Value from Previous Values FAQ
How does predictable exact value from previous values work?
It occurs when an attacker can predict the next random number or identifier based on previous ones, compromising cryptographic security and privacy.
Why is predictable exact value from previous values a concern in web applications?
Predictable values weaken encryption keys and session identifiers, making it easier for attackers to gain unauthorized access or perform other malicious activities.
How can I detect predictable exact value from previous values vulnerabilities?
Use static analysis tools to identify PRNGs with low entropy sources and dynamic testing to observe patterns in generated random numbers.
What are the best practices to prevent predictable exact value from previous values?
Increase entropy used for seeding PRNGs, use FIPS 140-2 approved random number generators, and periodically reseed PRNGs with high-quality sources of randomness.
How can I fix a predictable exact value from previous values vulnerability in Java?
Use SecureRandom class to generate cryptographically strong random numbers instead of java.util.Random.
Can you provide an example of vulnerable code for predictable exact value from previous values?
An example is using a PRNG with insufficient entropy, such as a linear congruential generator without proper seeding.
How can I ask AI to check my code for predictable exact value from previous values vulnerabilities?
Review the following Java code block for potential CWE-342 Predictable Exact Value from Previous Values vulnerabilities and rewrite it using SecureRandom class: [paste code here]
Vulnerabilities Related to Predictable Exact Value from Previous Values
| CWE | Name | Relationship | |—|—|—| | CWE-340 | Generation of Predictable Numbers or Identifiers | ChildOf |
References
- https://cwe.mitre.org/data/definitions/342.html
- https://owasp.org/Top10/2025/A04_2025-Cryptographic_Failures/
- https://nvd.nist.gov/
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 Predictable Exact Value from Previous Values and other risks before an attacker does.