Skip to content
Info disclosure Disclosed report Intermediate CVE-2018-5114

Overwrite of existing cookie with HttpOnly flagged cookie results in HttpOnly being ignored by Firefox

Firefox fails to apply the HttpOnly flag when a cookie is overwritten by a new Set-Cookie header that includes HttpOnly. An attacker who can set a cookie without HttpOnly (e.g., via a subdomain or network position) can later have the server set it with HttpOnly, but the flag is ignored, leaving the cookie accessible to JavaScript and XSS.

inkognito Follow

Originally disclosed on Mozilla

  • Fixed in 21 days
  • Paid in 45 days
  • Disclosed after 21 days
Text
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36

Steps to reproduce:

A HTTP Request is sent to the server (192.168.1.1), which responds with with a Set-Cookie (without HttpOnly flag) statement to set a cookie:
Example Response:

HTTP/1.1 302 Found
Content-Type: text/html
Content-Length: 287
Location: http://192.168.1.1/webpage.php?id=1
Connection: close
Set-Cookie: PHPSESSID=qevb2lkbjviniu2i3ie278tp45; path=/

<...>



The cookie PHPSESSID is set in Firefox, and the Browser follows the Location redirect to the webpage (same server 192.168.1.1) issuing the following request:

GET /webpage.php?id=1 HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Referer: http://192.168.1.1/login.php
Cookie: PHPSESSID=qevb2lkbjviniu2i3ie278tp45
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1



This request results in the following response from the server setting a HttpOnly protected cookie (overwriting the existing one with additional HttpOnly flag):

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 303
Connection: close
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=qevb2lkbjviniu2i3ie278tp45; path=/; httponly
Vary: Accept-Encoding

<...>


Summary:
=========
"Upgrading/Overwriting" a normal cookie to a httponly flagged cookie.







Actual results:

The cookie is, although now flagged with httponly, still accessible via JavaScript:

PoC 1:
Web Console:

document.cookie
"PHPSESSID=qevb2lkbjviniu2i3ie278tp45"

PoC 2:
also works via Cross-Site Scripting vector, aka:
<script>alert(document.cookie)</script>
-> resulting in an alert box disclosing the cookie value


Expected results:

After setting the httpOnly flag, the cookie should be protected from accessing it via JavaScript. This is a Cross-Site Scripting prevention meassure which seems to not work as intended anymore (worked as intended in earlier versions of Firefox, and works as intended in other Browsers (Chrome)).

The original report as published on Mozilla's Bugzilla, by inkognito. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

What the attacker needed

Attacker can set a cookie without HttpOnly; server later sets same cookie with HttpOnly; victim uses Firefox

The fix

Firefox should correctly apply the HttpOnly attribute when overwriting an existing cookie.

How it was found

  1. Send a request to the server that responds with a Set-Cookie header without HttpOnly.
  2. The browser stores the cookie and follows a redirect to another page on the same server.
  3. The server responds with a Set-Cookie header for the same cookie name but with HttpOnly.
  4. Run document.cookie in the browser console to check if the cookie is still readable.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

HttpOnly is a cookie setting that stops JavaScript from reading the cookie, which helps protect session cookies from theft via cross-site scripting (XSS). This report shows that in Firefox, if a cookie is first set without HttpOnly and later overwritten with HttpOnly, the browser still lets JavaScript read it. That means the protection is lost.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.