Platform

Platform overview How it works Authorization testing Evidence & reports Private scanning Integrations

Solutions

Security agencies Product teams Regulated industries Partner programme

Learn

Blog Knowledge hub Compare

Resources

Pricing Documentation Help centre FAQ Security & data What we haven’t proved

Company

About Contact Careers Sign in to the platform Start a $199 pilot →

Home / Knowledge hub / HttpOnly cookie

Knowledge hub

HttpOnly cookie

A cookie that page scripts cannot read, so XSS cannot simply steal it.

Illustration explaining HttpOnly cookie

What it means

HttpOnly is a flag a server puts on a cookie to tell the browser that page scripts must not read it. The cookie is still sent with requests to your server. It simply does not appear in document.cookie, so JavaScript on the page cannot see or copy it.

The flag exists for one reason. If an attacker gets a script running on your page, the session cookie is the first thing they want. HttpOnly takes that easy prize off the table, which is why OWASP calls it a basic protection for session cookies.

Why it matters

A stolen session cookie lets someone act as the user without any password. With a cookie that scripts cannot read, an XSS flaw becomes harder to turn into session hijacking: the attacker cannot simply send the cookie value to their own server.

It is a cheap safeguard that is often missing on the one cookie that matters. It is also frequently set on the wrong cookie, protecting a harmless preference while the real session token stays readable. That gap shows in a security review as a quick, avoidable finding.

How it shows up

Frameworks usually set HttpOnly on the session cookie by default; custom cookies and tokens set by your own code do not always. A token stored in localStorage is always readable by script. Check the Set-Cookie header on login for HttpOnly, Secure and SameSite together.

The flag has limits that teams forget. A script running in the page can still make requests, and the browser attaches the cookie, so an attacker can act as the user from inside the page without ever seeing the value. HttpOnly narrows XSS damage and does not remove XSS. Fix the flaw too.

Questions people ask

HttpOnly cookie, answered

Does HttpOnly stop XSS?

No. It stops a script reading the cookie, nothing more. Injected script can still send requests from the user's browser with the cookie attached, change the page, and read other data it can see.

The vulnerability itself still needs fixing.

Which cookies should be HttpOnly?

Any cookie that is only for the server to read, above all the session cookie and any authentication cookie. Cookies that your front-end script needs to read, such as a theme choice, cannot be HttpOnly.

If in doubt, make it HttpOnly and see what breaks.

Can JavaScript still set an HttpOnly cookie?

Script cannot create or overwrite a cookie that is marked HttpOnly through document.cookie, in current browsers. The server sets it through the Set-Cookie header.

That is part of what makes it harder to tamper with from the page.

Is storing a token in localStorage worse than a cookie?

It is more exposed to XSS, because any script on the page can read localStorage. A cookie marked HttpOnly cannot be read that way. Cookies bring their own issue, cross-site request forgery.

See web storage security.

How do we check this?

Sign in and open the browser developer tools, find the session cookie, and look for the HttpOnly mark. Or read the Set-Cookie header in a proxy.

Also check that scripts in the console cannot print the value.

Cyberlop mark

Can a script walk off with the session?

We test whether your session cookies carry the protective flags and whether a script flaw could be turned into a stolen session, proving each finding with the request and response. Book a pilot on one app.

Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.