Wednesday, 2 November 2011
Misunderstandings on HttpOnly Cookie
HttpOnly Cookie is nothing new, it was first introduced by Microsoft back in 2002 when it released IE 6 SP1. Of course I don't think HttpOnly alone can solve all XSS problems but I believe it is a useful feature if used correctly. And while I don't think we can set every cookie with HttpOnly flag, at least we should set it on all session cookies whenever possible. However, statistics [1] show that only about 9% of websites use HttpOnly cookies. I don't know exactly why the usage rate is so low, but I think it may be related to the following misunderstandings:
1) HttpOnly is only for IE
No.
According to Google's Browser Security Handbook [2] and OWASP [3], almost 99% of all browsers (the only exception is Android) support HttpOnly cookies.
| Test description | MSIE6 | MSIE7 | MSIE8 | FF2 | FF3 | Safari | Opera | Chrome | Android |
| Is httponly flag supported? | YES | YES | YES | YES | YES | YES | YES | YES | NO |
2) On .NET platform, it's disabled by default
Yes and No.
For custom application cookies, you have to manually enable it, but for session cookies, it is enabled by default.
Starting from .NET 2.0 (which was released in 2005, three years after HttpOnly was introduced), all session cookies come with the HttpOnly flag, and you can't even disable it. When decompiling that part of .NET program code, you will see:
System.Web.SessionState.SessionIDManager
private static HttpCookie CreateSessionCookie(string id)
{
HttpCookie cookie = new HttpCookie(Config.CookieName, id);
cookie.Path = "/";
cookie.HttpOnly = true; // <-- burned in, not configurable
return cookie;
}
The <httpCookies httpOnlyCookies="true" …> in web.config is only for custom application cookies, not for session cookies.
3) Most Java Application Servers don't support HttpOnly cookies
No.
But it is true that Java's support for the HttpOnly flag is very slow. There was no setHttpOnly() method in javax.servlet.http.Cookie until Java EE 6 (Servlet API 3.0) which was just released in December 2009. However, this doesn't mean application servers can't support HttpOnly without Java EE 6.
| Type | Support HttpOnly Since | Comment |
| Tomcat | 5.5.28[4] or 6.0.20 | Default "false" for 5.5.28 to 6.0. Default "true" for 7.0+ |
| JBoss# | 6.0 | Servlet 3.0, default "false", config via web.xml <cookie-config> |
| WebLogic | 9.2 MP4[5] | Servlet 2.4, default "true" |
| WebSphere## | 8.0[6] | Servlet 3.0, default "true", can config via console as well |
##: According to IBM [7], the custom property addHttpOnlyAttributeToCookies on WAS 6.1 and 7.0 does not affect every cookie that passes through the application server. The list of non-HTTPOnly cookies includes JSESSIONID cookies.
Summary
As you can see, many application servers already support HttpOnly cookies, some even set the HttpOnly flag on session cookies by default. The risk of setting HttpOnly flag on session cookies should be pretty low, and the steps for enabling it are not difficult. Therefore, if your web application is running on a “supported but default false” application server, such as Tomcat 6.0, you should enable it.
References:
[1] http://w3techs.com/technologies/details/ce-httponlycookies/all/all
[2] http://code.google.com/p/browsersec/wiki/Part2
[3] https://www.owasp.org/index.php/HTTPOnly
[4] http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
[5] http://download.oracle.com/docs/cd/E13222_01/wls/docs92/webapp/weblogic_xml.html#wp1071982
[6] http://publib.boulder.ibm.com/infocenter/ieduasst/v1r1m0/index.jsp?topic=/com.ibm.iea.was_v8/was/8.0/Security/WASv8_SecurityEnhancements/player.html
[7] http://www-1.ibm.com/support/docview.wss?rs=180&uid=swg27004980







