A fundamental security control for protecting session cookies from XSS attacks.
HttpOnly is a security attribute that can be set on a cookie to prevent client-side
JavaScript from accessing it. When a cookie is marked with HttpOnly, browsers will block
attempts to read it through document.cookie, which makes it significantly harder for
attackers to steal session identifiers during an XSS (Cross-Site Scripting) attack.
Set-Cookie: session_id=abc123; HttpOnly; Secure; SameSite=Lax
In this example, the cookie is:
HttpOnly)Secure)SameSite=Lax)
Without HttpOnly, a simple XSS payload like the one above can expose all cookies to an attacker.
With HttpOnly enabled, this attempt fails, and the cookie remains protected.