Cross-Site Scripting (XSS) is categorized as one of the OWASP Top 10 Security Vulnerabilities. The HttpOnly
flag directs compatible browsers to prevent client-side script from accessing cookies. Including the HttpOnly
flag in the Set-Cookie HTTP response header for a sensitive cookie helps mitigate the risk associated with XSS where an attacker's script code attempts to read the contents of a cookie and exfiltrate information obtained.
Cookies without the HttpOnly
flag set are accessible to client-side scripts (such as JavaScript) running in the same origin.
+In case of a Cross-Site Scripting (XSS) vulnerability, the cookie can be stolen by a malicious script.
+If a sensitive cookie does not need to be accessed directly by client-side scripts, the HttpOnly
flag should be set.
Use the HttpOnly
flag when generating a cookie containing sensitive information to help mitigate the risk of client side script accessing the protected cookie.
Use the HttpOnly
flag when generating a cookie containing sensitive information to help mitigate the risk of client-side scripts accessing the protected cookie.