Home » Web Development
HttpOnly in PHP (Anti-XSS)
Posted on September 5th, 2004 1 Comment »
Wondering how to prevent JavaScript from stealing session cookie? Major browsers got the answer: just add HttpOnly to cookie to protect it from malicious JavaScript code. Full details:
http://msdn.microsoft.com/workshop/author/dhtml/httponly_cookies.asp
Since this option is well-supported (AFAIK MSIE, Mozilla/Firefox/Gecko and Konqueror support it) it’s unclear why PHP doesn’t support it yet. Here’s a patch to add HttpOnly support to PHP:
After applying the patch, add this string to your php.ini:
session.cookie_httponly = 1
Enjoy!


One Response
The Mozilla browsers currently do not support the httponly option. Have a look at bug 178993: http://bugzilla.mozilla.org/show_bug.cgi?id=178993