HttpOnly Cookies
An HttpOnly cookie is a cookie that carries a special setting telling the web browser it should only be sent to the server and not be readable by JavaScript running on the page. This helps protect sensitive cookies, such as those used to keep a user logged in, from being stolen if a malicious script manages to run in the browser. It is a technical security measure rather than a consent or privacy-preference setting.
HttpOnly is an attribute set on an HTTP cookie (typically via the Set-Cookie response header) that instructs the browser to withhold the cookie value from client-side scripting interfaces such as document.cookie, so the cookie is transmitted only in HTTP(S) requests to the server. Its primary purpose is to reduce the risk of session or cookie theft via cross-site scripting (XSS) by preventing browser-executed JavaScript from reading the cookie's value. HttpOnly is often applied to session cookies and is distinct from, and can be combined with, the Secure attribute, which restricts a cookie to encrypted HTTPS connections. Note that HttpOnly is a security control governing script access to cookie contents; it does not by itself determine whether a cookie is exempt from or subject to consent requirements under the ePrivacy Directive or its national implementations, nor whether associated processing complies with the GDPR or other applicable privacy laws, those obligations depend on the cookie's purpose and the data processed, which are outside the scope of this attribute.
Why it matters
HttpOnly cookies address one of the most common ways attackers attempt to hijack authenticated sessions. When a session cookie can be read by JavaScript running in the page, a successful cross-site scripting (XSS) attack can extract that cookie value and use it to impersonate the user. By marking a cookie HttpOnly, the browser withholds its value from client-side scripting interfaces, which makes it harder for many XSS attacks to steal session identifiers even if malicious script manages to execute. For teams responsible for protecting user accounts, this is a foundational hardening measure for session management.
For privacy and compliance professionals, it is important to keep HttpOnly in its proper lane. It is a technical security control that governs whether scripts can read a cookie's contents; it is not a consent mechanism or a privacy-preference setting. Whether a cookie must be disclosed, consented to, or logged depends on the cookie's purpose and the data processed, not on whether the HttpOnly attribute is set. A cookie can be HttpOnly and still require prior consent under the ePrivacy rules in most EU jurisdictions if it is used for non-essential purposes, and conversely a strictly necessary session cookie may be exempt from consent regardless of the attribute.
Understanding this distinction helps organizations avoid a common misconception that setting security attributes on cookies satisfies privacy obligations. Security controls such as HttpOnly and consent obligations under the ePrivacy Directive, GDPR, or US state privacy laws operate on different legal and technical planes, and each must be assessed on its own terms.
Who it's relevant to
Inside HttpOnly Cookies
Common questions
Answers to the questions practitioners most commonly ask about HttpOnly Cookies.

