A non-HttpOnly cookie is a browser cookie that JavaScript can read and write through document.cookie. Because it is accessible to scripts, it can be stolen or altered by injected code, so sensitive session data is usually marked HttpOnly instead.
Why non-HttpOnly cookies are dangerous
A non-HttpOnly cookie can be read and changed by JavaScript, which means any injected script running in the page context may be able to steal session values or tamper with state. That makes the cookie itself part of the browser’s script-exposed attack surface, not just a passive storage container.
The practical security difference is not the cookie format, but whether scripts are allowed to touch it. If a site stores authentication or session data in a readable cookie, a successful cross-site scripting issue can turn into session theft, request forgery support, or silent manipulation of browser-held values.
How browsers expose cookie data to scripts
When a cookie is not marked HttpOnly, client-side code can access it through document.cookie. That access is broad: any same-origin script with execution in the page can usually read the cookie string and write updated values, subject to the cookie’s scope rules.
Because the browser does not distinguish between trusted application code and injected code at this layer, the control boundary is really the integrity of JavaScript execution. If an attacker can execute script in the origin, they can often reach any non-HttpOnly cookie that the page can reach.
This is why the attribute matters more for credentials and session identifiers than for harmless preference cookies. A readable cookie that carries a login session, CSRF token, or other sensitive bearer value creates a direct path from script execution to account abuse.
Why HttpOnly is the usual default for sensitive session data
For session cookies and other authentication state, HttpOnly reduces exposure by making the value unavailable to JavaScript. That does not stop every browser-side attack, but it removes a major theft path and raises the bar for turning a scripting bug into credential compromise.
Used alongside Cookie Security Guide, this is part of the broader rule that cookie attributes should match the data’s sensitivity. The same page-level hardening should also be read with Security Headers Guide, because script exposure is rarely a standalone problem.
For browser-token decisions, Browser Storage Security Guide helps compare cookies with other storage locations, while Session Cookies vs Bearer Tokens explains why some applications prefer server-managed sessions over browser-readable bearer material.
Where this fits in web session security
Non-HttpOnly cookies are best understood as a browser-session design choice, not a standalone vulnerability class. They become dangerous when they hold values that should survive only on the server side or remain hidden from script, especially in applications with rich client-side execution.
That is why mature web security guidance usually pairs cookie flags with XSS prevention, secure session handling, and careful token placement. A readable cookie increases the blast radius of client-side compromise, while a properly scoped session cookie limits what injected code can exfiltrate.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V7 — Session Management | HttpOnly cookie handling is part of browser session protection and token exposure control. |
| Recommendation — Require HttpOnly for session cookies that must not be readable by JavaScript. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Cookie-held session material functions like credential or authenticator lifecycle material. |
| SC-23 — Session Authenticity | Readable session cookies affect whether browser state can be trusted against script abuse. | |
| Recommendation — Manage session-related secrets so they are not exposed to client-side script access. Protect session state so client-side manipulation cannot subvert authenticated sessions. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Cookie attribute hardening is a web application security safeguard against script-driven theft. |
| Recommendation — Harden web applications so sensitive cookies are not script-readable. | ||
Practitioner Guidance
Common misunderstanding: A cookie that is merely “secure” or “same-site” is not automatically safe for sensitive values. Those attributes address transport and request context, but they do not stop JavaScript from reading the cookie if HttpOnly is missing.
What to watch for: Review any cookie that carries session identifiers, refresh tokens, or other bearer data and ask whether the browser truly needs script access. If it does not, make it HttpOnly and treat any remaining readable cookies as low sensitivity by design.
Related resources from NHI Mgmt Group
- HttpOnly Cookie
- What happens when an organisation does not fix non-compliant cookie consent after a regulator order?
- Why does cookie consent fail when access to the website depends on accepting non essential cookies?
- How should website operators implement cookie consent so that non-essential tracking only starts after valid user consent?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org