CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag
Official CWE-1004 CWE context with Glexia analysis, remediation guidance, related CVEs, and ATT&CK context.
Glexia's Take
CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag
Sensitive Cookie Without 'HttpOnly' Flag represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.
Executive Impact
- Confidentiality: Read Application Data: If the HttpOnly flag is not set, then sensitive information stored in the cookie may be exposed to unintended parties.
- Integrity: Gain Privileges or Assume Identity: If the cookie in question is an authentication cookie, then not setting the HttpOnly flag may allow an adversary to steal authentication data (e.g., a session ID) and assume the identity of the user.
Developer Pattern
CWE-1004 is the kind of defect developers can usually prevent with explicit validation, safer framework defaults, and tests that exercise hostile input or unsafe state transitions.
Confidence
high confidence from CWE-1004, 4.20.
Official CWE Definition
CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag
The product uses a cookie to store sensitive information, but the cookie is not marked with the HttpOnly flag.
Developer And Remediation Guidance
How teams prevent and detect this weakness
Causes
- 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. The snippet of code below establishes a new cookie to hold the sessionID.,The HttpOnly flag is not set for the cookie. An attacker who can perform XSS could insert malicious script such as:,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.,To mitigate the risk, use the setHttpOnly(true) method.
Remediation
- Implementation: Leverage the HttpOnly flag when setting a sensitive cookie in a response.
Detection
- Automated Static Analysis: 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.)
Mappings
Related CVEs, CWEs, and ATT&CK context
ATT&CK Relevance
ATT&CK relevance is shown only when reviewed or responsibly inferred.