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.

CWE-341

Don't catalog this weakness. Prove it's reachable.

Plexicus turns CWE catalogs into evidence: every CWE-pattern is matched against your real code graph, reach is proven on a sandbox clone, and verified findings ship as reviewed PRs.

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 to validate what matters?

Ready to validate what matters?

Plexicus is Proof-Driven AppSec: validated findings, contextual understanding, and reviewed remediation — anchored in evidence, scoped with you.

Qualification

Check whether AI Swarm Pentest fits your environment.

Share the minimum context. We will review the scope and tell you the next commercial step.

Before submitting — verify you fit

Teams with fewer than 50 developers: start a 14-day Trial instead of booking a demo. Start a 14-day Trial →

0 / 280

No commitment. If you don't fit, we'll tell you.

SAMPLE HANDOVER · ILLUSTRATIVE

Sample evidence handover

A trimmed view of what your team receives at the end of an AI Swarm Pentest engagement. Real engagements include full technical evidence, executive narrative, and a remediation plan.

VALIDATED FINDING Evidence attached

Server-Side Request Forgery in webhooks/receiver

demo-project/sample-app · src/webhooks/receiver.py:42

SeverityHigh CVSS 3.18.6 Priority79 Confirmedvia replay

Untrusted caller-supplied URLs reach an internal egress without an allowlist. Replayed in a sandbox against a fresh authorised target — the same control was validated to fail twice.

REVIEWER-READY REMEDIATION Merge-ready PR

Validate the target URL against an allowlist of permitted hostnames. Reject private/internal IP ranges. Enforce HTTPS only.

plexicus/remediation/webhooks-ssrf 3 changed · 0 new files
42resp = requests.get(target_url)
42+if not is_allowed_host(target_url):
43+  raise WebhookRejected(target_url)
44+resp = requests.get(target_url, timeout=5)
Every engagement hands over:
  • Executive briefing
  • Validated findings list
  • Merge-ready PRs
  • Compliance mapping (NIS2 · DORA · CRA)