HttpOnly Cookie Flag (HttpOnly Flag)
Why HttpOnly Flag Matters
XSS attacks frequently target session cookies because stealing a session cookie gives the attacker full access to the victim's account. Without HttpOnly, a single XSS vulnerability allows attackers to exfiltrate all cookies using document.cookie and send them to their server.
With HttpOnly, even a successful XSS attack cannot directly steal the session cookie. The attacker can still make requests to your API using the victim's browser (since cookies are sent automatically), but they cannot exfiltrate the cookie to use from their own machine. This limits the attack's duration to the browser session.
HttpOnly should be set on all session cookies and authentication tokens. Cookies that need to be read by JavaScript (like CSRF tokens stored in cookies or UI preference cookies) cannot use HttpOnly, but these should not contain sensitive session data.
Checking Your Setup
A security audit checks the HttpOnly flag on all cookies. Session cookies and authentication tokens must have HttpOnly set. CSRF tokens stored in cookies may need to omit HttpOnly if your JavaScript needs to read them, but consider alternative CSRF token delivery methods.
Run a Security Audit