Skip to content

Sensitive Cookie Without 'HttpOnly' Flag

Description

A new cookie is created without the HttpOnly flag set. The HttpOnly flag is a directive to the browser to make sure that the cookie cannot be read by malicious scripts. When a user is the target of a "Cross-Site Scripting", the attacker would benefit greatly from getting the session id for example.

Examples

Insecure Code

scala
val C = new javax.servlet.http.Cookie("session", "123");
response.addCookie(C);

Secure Code

scala
val C = new javax.servlet.http.Cookie("session", "123");
C.setHttpOnly(true);
response.addCookie(C);

Remediation

Set the HttpOnly flag to true when creating a new cookie, e.g., $C.setHttpOnly(true);

Rule Details

FieldValue
IDCODE-0007
CategoryWeb
SeverityLOW
CWECWE-1004
ConfidenceHIGH
ImpactLOW
LikelihoodMEDIUM
ExploitabilityEASY
Tagscookie, httpOnly
OWASPN/A