What Are HttpOnly Cookies? A Simple Guide to Secure Sessions

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. How it works The server sets the cookie with a Set-Cookie response header and adds the HttpOnly flag. The browser
…