An HttpOnly cookie is a browser cookie marked with the HttpOnly attribute. This prevents client-side JavaScript from reading its value through APIs such as document.cookie. Browsers still send the cookie with matching HTTP requests, so servers can use it to maintain a user’s session.
Setting this flag helps limit the damage from cross-site scripting by making it harder for injected scripts to steal a session cookie directly. It is not a complete defense: malicious JavaScript running on an authenticated page may still be able to send requests as the user, even without seeing the cookie value. Use HttpOnly alongside protections such as secure cookie settings, a restrictive Content Security Policy, and defenses against cross-site scripting and request forgery.


