Cookie Without the HttpOnly Attribute

A sensitive cookie is set without the HttpOnly attribute, so script running in the page, including script injected through cross-site scripting, can read its value.

SeverityInformational
CVSS 3.10 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:N/A:N Open in the calculator
CVSS 4.00 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-1004: Sensitive Cookie Without 'HttpOnly' Flag
OWASP Top 10A02:2025 Security Misconfiguration
CategorySecurity Misconfiguration

Description

The application sets one or more sensitive cookies, such as session identifiers or authentication tokens, without the HttpOnly attribute. The attribute stops script in the page reading or changing the cookie through document.cookie, while the browser still sends it with requests as normal. Without it, any script running in the application's origin can read the cookie's value.

The attribute is a defence-in-depth measure against cross-site scripting, and its absence has no direct impact of its own. If the application has a cross-site scripting flaw, an attacker exploiting it can read the cookie, send it to a server they control and then use the session from their own browser until it expires or is ended, without depending on the victim's page staying open. The attribute does not prevent cross-site scripting, and injected script can still send requests that carry the cookie and act as the user, but with it set the attacker is limited to acting through the victim's browser while the injected script runs, because the session identifier itself cannot be copied out and reused elsewhere.

Some cookies, such as anti-forgery tokens using the double-submit pattern or settings read by client-side code, must be readable by script and so cannot carry the attribute. The issue is identified by inspecting the Set-Cookie headers or the browser's cookie storage, and confirmed for a given cookie by reading document.cookie in the browser's console.

Remediation

Set the HttpOnly attribute on every cookie that carries a session identifier, authentication token or other value that client-side code does not need to read:

  • Use the framework or server setting for session cookies, for example session.cookie_httponly in PHP, httpOnlyCookies on httpCookies in ASP.NET, Cookie.HttpOnly in ASP.NET Core cookie options, cookie.httpOnly in express-session, or <http-only>true</http-only> under session-config and cookie-config in a Java web.xml.
  • Where client-side code reads a sensitive cookie, change the design so that script does not need the value.
  • Set Secure and an appropriate SameSite value on the same cookies.
Set-Cookie: __Host-id=38afes7a8; Secure; HttpOnly; SameSite=Lax; Path=/

Treat the attribute as a complement to preventing cross-site scripting, not a substitute for it. Confirm the fix by inspecting the Set-Cookie headers after login and checking that the session cookie no longer appears in document.cookie.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding