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.
| Severity | Informational |
| CVSS 3.1 | 0 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.0 | 0 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 |
| CWE | CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag |
| OWASP Top 10 | A02:2025 Security Misconfiguration |
| Category | Security 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_httponlyin PHP,httpOnlyCookiesonhttpCookiesin ASP.NET,Cookie.HttpOnlyin ASP.NET Core cookie options,cookie.httpOnlyin express-session, or<http-only>true</http-only>undersession-configandcookie-configin a Javaweb.xml. - Where client-side code reads a sensitive cookie, change the design so that script does not need the value.
- Set
Secureand an appropriateSameSitevalue on the same cookies.
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 trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.