CWE-341 Base Borrador

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,…

Definición

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.
Impacto en el mundo real

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.

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

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

Ejemplo de código vulnerable

Vulnerable PHP

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

Vulnerable PHP
function generateSessionID($userID){
  	srand($userID);
  	return rand();
  }
Ejemplo de código seguro

Secure pseudo

Seguro 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.
Lista de prevención

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.
Señales de detección

How to detect CWE-341

SAST High

Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.

DAST Moderate

Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.

Runtime Moderate

Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.

Code review Moderate

Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-341 y abre un PR de corrección en menos de 60 segundos.

Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.

Preguntas frecuentes

Frequently asked questions

¿Qué es 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.

¿Qué gravedad tiene CWE-341?

MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.

¿Qué lenguajes o plataformas se ven afectados por CWE-341?

MITRE no ha especificado plataformas afectadas para esta CWE — puede aplicar a la mayoría de los stacks de aplicaciones.

¿Cómo puedo prevenir 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").

¿Cómo detecta y corrige Plexicus CWE-341?

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-341 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.

¿Dónde puedo aprender más sobre CWE-341?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/341.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.

Listo cuando tú lo estés

Deja de pagar por desarrollador.
Empieza a cerrar el bucle.

Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.