CWE-784 Variante Borrador High likelihood

Reliance on Cookies without Validation and Integrity Checking in a Security Decision

This vulnerability occurs when an application makes security decisions—like granting access or verifying identity—based solely on cookie data without first confirming the cookie's authenticity or…

Definición

What is CWE-784?

This vulnerability occurs when an application makes security decisions—like granting access or verifying identity—based solely on cookie data without first confirming the cookie's authenticity or integrity.
Attackers can easily manipulate cookie values directly in the browser or by crafting custom client-side requests. Since the application trusts this data without validation, attackers can forge cookies to impersonate other users, bypass login screens, or escalate their privileges by inserting expected values. To prevent this, developers must never treat cookies as a trusted security mechanism on their own. Always validate and verify cookie integrity on the server using techniques like cryptographic signing, comparing against server-side sessions, or using secure, tamper-proof tokens instead of plain data.
Impacto en el mundo real

Real-world CVEs caused by CWE-784

  • Attacker can bypass authentication by setting a cookie to a specific value.

  • Attacker can bypass authentication and gain admin privileges by setting an "admin" cookie to 1.

  • Content management system allows admin privileges by setting a "login" cookie to "OK."

  • e-dating application allows admin privileges by setting the admin cookie to 1.

  • Web-based email list manager allows attackers to gain admin privileges by setting a login cookie to "admin."

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

  1. 1

    The following code excerpt reads a value from a browser cookie to determine the role of the user.

  2. 2

    The following code could be for a medical records application. It performs authentication by checking if a cookie has been set.

  3. 3

    The programmer expects that the AuthenticateUser() check will always be applied, and the "authenticated" cookie will only be set when authentication succeeds. The programmer even diligently specifies a 2-hour expiration for the cookie.

  4. 4

    However, the attacker can set the "authenticated" cookie to a non-zero value such as 1. As a result, the $auth variable is 1, and the AuthenticateUser() check is not even performed. The attacker has bypassed the authentication.

  5. 5

    In the following example, an authentication flag is read from a browser cookie, thus allowing for external control of user state data.

Ejemplo de código vulnerable

Vulnerable Java

The following code excerpt reads a value from a browser cookie to determine the role of the user.

Vulnerable Java
Cookie[] cookies = request.getCookies();
  for (int i =0; i< cookies.length; i++) {
  	Cookie c = cookies[i];
  	if (c.getName().equals("role")) {
  		userRole = c.getValue();
  	}
  }
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-784

  • Architecture and Design Avoid using cookie data for a security-related decision.
  • Implementation Perform thorough input validation (i.e.: server side validation) on the cookie data if you're going to use it for a security related decision.
  • Architecture and Design Add integrity checks to detect tampering.
  • Architecture and Design Protect critical cookies from replay attacks, since cross-site scripting or other attacks may allow attackers to steal a strongly-encrypted cookie that also passes integrity checks. This mitigation applies to cookies that should only be valid during a single transaction or session. By enforcing timeouts, you may limit the scope of an attack. As part of your integrity check, use an unpredictable, server-side value that is not exposed to the client.
Señales de detección

How to detect CWE-784

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-784 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-784?

This vulnerability occurs when an application makes security decisions—like granting access or verifying identity—based solely on cookie data without first confirming the cookie's authenticity or integrity.

¿Qué gravedad tiene CWE-784?

MITRE califica la probabilidad de explotación como Alta — esta debilidad se explota activamente en la práctica y debe priorizarse para su remediación.

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

MITRE lists the following affected platforms: Web Based.

¿Cómo puedo prevenir CWE-784?

Avoid using cookie data for a security-related decision. Perform thorough input validation (i.e.: server side validation) on the cookie data if you're going to use it for a security related decision.

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

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-784 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-784?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/784.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.