Firefox accepts control characters in cookies via document.cookie, which breaks the majority of websites
Firefox allows cookies set via document.cookie to contain control characters that are forbidden by RFC 6265. An attacker who can run JavaScript on a site can set such cookies, which then cause a permanent denial of service for the victim on many websites.
Originally disclosed on Mozilla
- Fixed in 13 days
- Paid in 15 days
- Disclosed after 13 days
Created attachment 9300047
Screen Shot 2022-10-24 at 10.06.17 PM.png
This issue is related to bug 1797231, but is considerably more serious and in my conversations with Dan Veditz should probably get fixed relatively quickly.
As in bug 1797231, Firefox allows certain cookie values that, when present, will cause a permanent denial-of-service attack on anyone whose cookie store has been poisoned by their presence. Unlike bug 1797231 however, this is due to Firefox allowing cookies to be set via document.cookie that contain control characters in defiance of RFC 6265: \x00-08, \x0A-x1F, and \x7F (delete).
These cookies can be created with the following Javascript (changing it up to 127 for delete)
'''
for (i=0; i<32; i++) {
let paddedIndex = i.toString().padStart(3, '0') + '_' + '0x' + i.toString(16).padStart(2, '0');
document.cookie=`cookie${paddedIndex}=-- ${String.fromCharCode(i)} --`;
}
'''
Firefox will allow these cookies to be created despite the fact that it seems to have code related to not allowing them via Set-Cookie:
https://searchfox.org/mozilla-central/source/netwerk/cookie/CookieCommons.cpp
'''c++
bool CookieCommons::CheckHttpValue(const CookieStruct& aCookieData) {
// reject cookie if value contains an RFC 6265 disallowed character - see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1191423
// NOTE: this is not the full set of characters disallowed by 6265 - notably
// 0x09, 0x20, 0x22, 0x2C, 0x5C, and 0x7F are missing from this list. This is
// for parity with Chrome. This only applies to cookies set via the Set-Cookie
// header, as document.cookie is defined to be UTF-8. Hooray for
// symmetry!</sarcasm>
const char illegalCharacters[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x3B, 0x00};
return aCookieData.value().FindCharInSet(illegalCharacters, 0) == -1;
}
'''
When created (see screenshot for what the console looks like), these cookies will permanently disable almost every site I tested: Facebook, Netflix, Github, Wikipedia, etc. Further, every request sent to a server running PHP seems to generate a permanent 400 error. I would hazard a guess that a significant percentage of the entire web can be rendered inaccessible if this code is able to run via XSS or any other method of code execution (such as allowed by playground sites).
These characters were almost certainly never intended to be allowed to be created via document.cookie, but seem to have bypassed the checks on them. Note that, unlike with the other bug which -does- affect Chromium, this bug only seems to affect Firefox.
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
Root cause
Likely, the code path for document.cookie does not apply the same validation as the Set-Cookie header, allowing control characters to be stored.
Impact
An attacker who can execute JavaScript (e.g., via XSS) could permanently disable many websites for the victim, including major sites and any PHP server, by setting these cookies.
What the attacker needed
Ability to run JavaScript on a site (e.g., XSS)
The fix
Firefox should reject control characters in cookies set via document.cookie, matching the validation used for Set-Cookie.
How it was found
- Run JavaScript that sets cookies with control characters via document.cookie.
- Observe that Firefox creates the cookies despite the characters being disallowed.
- Visit other websites and see that they are permanently disabled or return errors.
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.
Cookies are small pieces of data that websites store in your browser. Some characters are not allowed in cookies because they can break how servers read them. This report shows that Firefox lets JavaScript set cookies with those forbidden characters, and once set, those cookies can make many websites stop working for that user.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.