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.
Auswirkungen in der Praxis

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.

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  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).

Verwundbares Codebeispiel

Vulnerable PHP

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

Verwundbar PHP
function generateSessionID($userID){
  	srand($userID);
  	return rand();
  }
Sicheres Codebeispiel

Secure pseudo

Sicher 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.
Präventions-Checkliste

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.
Erkennungssignale

How to detect CWE-341

SAST High

Führe statische Analyse (SAST) auf der Codebasis aus und suche im Datenfluss nach dem unsicheren Muster.

DAST Moderate

Führe dynamische Application-Security-Tests gegen den Live-Endpoint aus.

Runtime Moderate

Beobachte Runtime-Logs auf ungewöhnliche Exception-Traces, fehlerhafte Eingaben oder Versuche, Autorisierung zu umgehen.

Code review Moderate

Code Review: Markiere jeden neuen Code, der Eingaben von dieser Oberfläche ohne validierte Framework-Helper verarbeitet.

Plexicus Auto-Fix

Plexicus erkennt CWE-341 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist 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.

Wie gravierend ist CWE-341?

MITRE hat für diese Schwachstelle keine Exploit-Wahrscheinlichkeit veröffentlicht. Behandle sie als mittlere Auswirkung, bis dein Threat Model anderes belegt.

Welche Sprachen oder Plattformen sind von CWE-341 betroffen?

MITRE hat für diese CWE keine betroffenen Plattformen spezifiziert — sie kann in den meisten Anwendungs-Stacks auftreten.

Wie kann ich CWE-341 verhindern?

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").

Wie erkennt und behebt Plexicus CWE-341?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-341 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-341?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/341.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.