Skip to content
Vol. 1 · Ed. 2026
CyberGlossary
Entry № 559

HttpOnly Cookie Flag

Reviewed byCybersecurity entrepreneur & security researcher

What is HttpOnly Cookie Flag?

HttpOnly Cookie FlagA cookie attribute that hides the cookie from JavaScript by forbidding access via 'document.cookie', limiting session theft when XSS is exploited.


The 'HttpOnly' attribute on 'Set-Cookie' marks a cookie as inaccessible to client-side scripts. The browser still attaches it to matching HTTP(S) requests, but neither 'document.cookie' nor any DOM or XHR API can read or modify it. Microsoft introduced the flag in Internet Explorer 6 SP1 during the 2002 Windows Security Push, specifically to blunt cookie theft from cross-site scripting; it is now standardised in RFC 6265 and its successor draft (6265bis).

For session and authentication cookies, 'HttpOnly' is essential because it stops the most common post-XSS escalation: harvesting the session identifier and replaying it from the attacker's machine. It is a damage-limiting control, not a fix — it does not prevent the XSS itself, stop CSRF, or block an attacker who simply drives authenticated requests through the victim's own browser. Combine it with 'Secure' (HTTPS-only transmission), 'SameSite' (cross-site send rules), the '__Host-' name prefix, short session lifetimes, and a strong Content Security Policy.

Cookies that front-end code must read — a CSRF double-submit token, a UI preference — intentionally omit 'HttpOnly'; keep those free of session secrets.

flowchart TD
  A[XSS payload runs in page] --> B{Session cookie HttpOnly?}
  B -- No --> C[document.cookie reads SID]
  C --> D[SID exfiltrated to attacker]
  D --> E[Session replayed, account hijacked]
  B -- Yes --> F[document.cookie cannot see SID]
  F --> G[Theft blocked; attacker limited to in-page actions]

● Examples

  1. 01

    'Set-Cookie: SID=abc; HttpOnly; Secure; SameSite=Lax; Path=/'.

  2. 02

    After an XSS, an attacker's payload cannot extract the session cookie because it is HttpOnly.

● Frequently asked questions

What is HttpOnly Cookie Flag?

A cookie attribute that hides the cookie from JavaScript by forbidding access via 'document.cookie', limiting session theft when XSS is exploited. It belongs to the Application Security category of cybersecurity.

What does HttpOnly Cookie Flag mean?

A cookie attribute that hides the cookie from JavaScript by forbidding access via 'document.cookie', limiting session theft when XSS is exploited.

How do you defend against HttpOnly Cookie Flag?

Defences for HttpOnly Cookie Flag typically combine technical controls and operational practices, as detailed in the full definition above.

What are other names for HttpOnly Cookie Flag?

Common alternative names include: HttpOnly attribute.

● Related terms

● See also