Tuesday, October 24. 2006
httpOnly cookies are a Microsoft extension to the cookie standard. The idea is that cookies marked as httpOnly cannot be accessed from JavaScript. This was implemented to stop cookie stealing through XSS vulnerabilities. This is unlike many people believe not a way to stop XSS vulnerabilities, but a way to stop one of the possible attacks (cookie stealing) that are possible through XSS.
Unfortunately the mozilla family still refuses to implement httpOnly cookies in Firefox and therefore their newest release: Firefox 2.0 still comes without support for httpOnly cookies. Luckily an annoying bug within the Firefox internals was fixed in Firefox 2.0 which enables an extension to correctly intercept incoming and outgoing cookies. In previous Firefox versions it was not possible to intercept incoming cookies, because the Cookie header was already parsed before the examine response hook was called.
Therefore I sat down during the last hours and wrote my little httpOnly extension. This extension adds transparent httpOnly cookie support to Firefox by using a funny hack.
The idea of the extension is to create a random key in the Firefox preferences on the first startup. It then hooks the hooks for outgoing and incoming HTTP requests. It then parses all incoming cookies (for now only Set-Cookie header) and rewrites cookies marked as httpOnly. Their name gets a 'hO_' prefix and their content gets AES encrypted. The key used for this encryption is based on the key stored in the preferences and the real name of the cookie. This results in Firefox storing an encrypted cookie into it's cookie storage. Of course it is still possible for JavaScript to read this cookie, but because the content is encrypted it is not possible for malicious JavaScript to retrieve the original value. All outgoing cookies on the other hand will be processed by another hook and decrypted if they are 'hO_' prefixed.
With this little hack it is now possible to have httpOnly cookies in Firefox 2.0. You can download this little extension from here. Be warned that this was a hack of only a few hours. Therefore you should only consider it a proof of concept. However I am planning on improving it in the near future.
Update: I just uploaded the extension to addons.mozilla.org.