CodePark/ questions / Cookies & browser storage
START PRACTICINGPRACTICE
Frontend question · Browser & web performance › Cookies & browser storage

What does the HttpOnly cookie attribute do?

Prevents JavaScript from reading the cookie through document.cookie

HttpOnly hides the cookie from scripts, so document.cookie can't read it. This limits the damage of XSS (an attacker's script running in your page).

"Sends the cookie only over HTTP" is the tempting wrong answer, because of the name. Sending only over HTTPS is the
Secure attribute. Blocking cross-site requests is SameSite. A cookie is deleted when the browser closes if it has no Expires or Max-Age. That is a session cookie, not HttpOnly.