CWE-341 Base Draft

Predictable from Observable State

This vulnerability occurs when an attacker can guess or deduce sensitive values, like random numbers or identifiers, by observing predictable system or network characteristics such as timestamps,…

Definition

What is CWE-341?

This vulnerability occurs when an attacker can guess or deduce sensitive values, like random numbers or identifiers, by observing predictable system or network characteristics such as timestamps, process IDs, or other public information.
This weakness undermines security by making supposedly random or secret values guessable. Instead of being truly unpredictable, these values follow a pattern or are derived from observable system state, like the current time, incrementing counters, or publicly accessible identifiers. Attackers can exploit this to predict session tokens, cryptographic nonces, or temporary file names, leading to unauthorized access or data breaches. To prevent this, developers must ensure that all security-critical values are generated using cryptographically secure random number generators (CSPRNGs) designed to resist prediction. Avoid using predictable sources like system time, process IDs, or unseeded pseudo-random functions for secrets, tokens, or initialization vectors. Always validate that randomness sources are appropriate for the security context of the feature you are building.
Real-world impact

Real-world CVEs caused by CWE-341

  • Mail server stores private mail messages with predictable filenames in a world-executable directory, which allows local users to read private mailing list archives.

  • PRNG allows attackers to use the output of small PRNG requests to determine the internal state information, which could be used by attackers to predict future pseudo-random numbers.

  • DNS resolver library uses predictable IDs, which allows a local attacker to spoof DNS query results.

  • MFV. predictable filename and insecure permissions allows file modification to execute SQL queries.

How attackers exploit it

Step-by-step attacker path

  1. 1

    This code generates a unique random identifier for a user's session.

  2. 2

    Because the seed for the PRNG is always the user's ID, the session ID will always be the same. An attacker could thus predict any user's session ID and potentially hijack the session.

  3. 3

    This example also exhibits a Small Seed Space (CWE-339).

Vulnerable code example

Vulnerable PHP

This code generates a unique random identifier for a user's session.

Vulnerable PHP
function generateSessionID($userID){
  	srand($userID);
  	return rand();
  }
Secure code example

Secure pseudo

Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Prevention checklist

How to prevent CWE-341

  • Implementation Increase the entropy used to seed a PRNG.
  • Architecture and Design / Requirements Use products or modules that conform to FIPS 140-2 [REF-267] to avoid obvious entropy problems. Consult FIPS 140-2 Annex C ("Approved Random Number Generators").
  • Implementation Use a PRNG that periodically re-seeds itself using input from high-quality sources, such as hardware devices with high entropy. However, do not re-seed too frequently, or else the entropy source might block.
Detection signals

How to detect CWE-341

SAST High

Run static analysis (SAST) on the codebase looking for the unsafe pattern in the data flow.

DAST Moderate

Run dynamic application security testing against the live endpoint.

Runtime Moderate

Watch runtime logs for unusual exception traces, malformed input, or authorization bypass attempts.

Code review Moderate

Code review: flag any new code that handles input from this surface without using the validated framework helpers.

Plexicus auto-fix

Plexicus auto-detects CWE-341 and opens a fix PR in under 60 seconds.

Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.

Frequently asked questions

Frequently asked questions

What is CWE-341?

This vulnerability occurs when an attacker can guess or deduce sensitive values, like random numbers or identifiers, by observing predictable system or network characteristics such as timestamps, process IDs, or other public information.

How serious is CWE-341?

MITRE has not published a likelihood-of-exploit rating for this weakness. Treat it as medium-impact until your threat model proves otherwise.

What languages or platforms are affected by CWE-341?

MITRE has not specified affected platforms for this CWE — it can apply across most application stacks.

How can I prevent CWE-341?

Increase the entropy used to seed a PRNG. Use products or modules that conform to FIPS 140-2 [REF-267] to avoid obvious entropy problems. Consult FIPS 140-2 Annex C ("Approved Random Number Generators").

How does Plexicus detect and fix CWE-341?

Plexicus's SAST engine matches the data-flow signature for CWE-341 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.

Where can I learn more about CWE-341?

MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/341.html. You can also reference OWASP and NIST documentation for adjacent guidance.

Ready when you are

Don't Let Security
Weigh You Down.

Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.