HttpOnly
HttpOnly
is an additional flag included in a Set-Cookie HTTP response header, which helps to mitigate the risk of client side script accessing the protected cookie.
If the
HttpOnly
flag is included in the HTTP response header, the cookie
cannot be accessed through client side script (if the browser supports this flag). As a
result, even if a cross-site scripting (XSS) flaw exists, and a user accidentally
accesses a link that exploits this flaw, the browser will not reveal the cookie to a
third party.
Example configuration:
<IfModule mod_headers.c>
Header edit Set-Cookie ^(?!IGNOREME=).*$ $0;HttpOnly;secure
</IfModule>
Sometimes, it may be essential to make cookies available to javascript. The
above configuration example provides a mechanism to specify that certain cookies should
not have the
HttpOnly
flag set. If a particular cookie is not a
candidate for the
HttpOnly
attribute, then replace the string
IGNOREME
with the cookie name in the configuration above.
To avoid the
HttpOnly
flag from being added to the response
cookie called MYCOOKIE1, run the following command to replace
IGNOREME
with
MYCOOKIE1
:
Header edit Set-Cookie ^(?!MYCOOKIE1).*$ $0;HttpOnly;
To exclude multiple cookies, run the following command:
Header edit Set-Cookie ^(?!(IGNOREME=|IGNOREME1=)).*$ $0;HttpOnly;