Open DevTools on a site you're logged into and type document.cookie . Your session cookie is usually missing from the output. The browser has it and sends it with every request, so why can't you see it?
Because it's marked HttpOnly .
The mental model: a sealed envelope
An HttpOnly cookie is a sealed envelope the browser carries for you. The browser delivers it to the server on every request, but JavaScript on the page can't open it, read it or change it.
That's the whole idea. The server writes the envelope, the browser carries it, the server reads it. Scripts never touch it.
Scripts are locked out of the jar, but the browser still attaches the cookie to requests they make. That is why HttpOnly limits XSS instead of stopping it.
How it works
The server sets the cookie with a Set-Cookie response header and adds the HttpOnly flag.
The browser stores it in its cookie jar like any other cookie.
On every matching request , the browser attaches it in the Cookie header.…