Content-Type: multipart/x-mixed-replace allows Set-Cookie in response parts
Firefox allows Set-Cookie headers inside multipart/x-mixed-replace response parts, so an attacker who controls the Content-Type and body of a response can set cookies on the domain. This bypasses protections like Grafana's Set-Cookie stripping and CSP sandbox.
Originally disclosed on Mozilla
- Fixed in 2 months
- Paid in 2 months
- Disclosed after 2 months
Summary
When Firefox encounters a response with the Content-Type of multipart/x-mixed-replace it will parse the response and update the document based on what is returned inside a given --BOUNDARY. Each response block
--BOUNDARY
Content-Type: text/html
data
It is allowed to set its own Content-Type.
I stumbled upon this Tweet https://x.com/ankursundara/status/1723410507389129092 where someone described an odd behavior in Firefox. The tweet mentions that you can also add Content-Security-Policy to each block, and this policy will be mixed in with the original policy given for the main response (this has some issues of its own but could be argued to work as expected).
I decided to test if any other headers could be altered inside these blocks. I found that contrary to Safari (Chrome handles x-mixed-replace differently), Firefox allows for Set-Cookie headers to be added inside each block, and they will get added to the current domain.
Issue
Any user that can set the Content-Type and control the response body of the request will be able to also set cookies on the domain.
I have found two examples of where this is an issue (just to prove the point):
-
Grafana (the monitoring platform) has a "proxy endpoint" where users can access requests to other services and have the response presented under grafana.example.com. To make this "safe" Grafana is stripping any
Set-Cookieheaders from the response, and also set a "Content-Security-Policy: sandbox" on the response. This makes the feature safe to use in most browsers. Using theContent-Type: multipart/x-mixed-replaceandSet-Cookietrick here will allow to bypass this protection in Firefox. -
The site https://webhook.site is a testing tool for webhooks. You can create a custom webhook like https://webhook.site/RANDOM where they allow you to configure the
Content-Typeand the response body of the response from your webhook test site. Even if you are only allowed to control theContent-Typeand the body you can use the issue here to bypass this and injectSet-Cookieheaders.
I tried to set some additional headers like Alt-Svc in the subparts but this did not work. The ones I got working in each sub block was
Content-Type Content-Disposition Content-Security-Policy Set-Cookie
POC
I used a simple PHP site like this
<?php
header("Content-Type: multipart/x-mixed-replace; boundary=TEST");
?>
--TEST
Set-Cookie: testcookie=testvalue
<h1>Test</h1>
--TEST--
Then visit the site and see the <h1> render. Now look at the request in dev tools. You will see that the original request does not include any Set-Cookie header, but looking at the Storage tab, you can see the cookie has been set.
(this is my POC page https://joaxcar.com/firefox/cookie.php)
/Johan
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
Impact
An attacker who can control the Content-Type and body of a response can set cookies on the domain, bypassing protections like Grafana's Set-Cookie stripping and CSP sandbox in Firefox.
What the attacker needed
Control Content-Type and response body; victim uses Firefox
How it was found
- Create a PHP page that sends a multipart/x-mixed-replace response with a boundary.
- Include a part with a Set-Cookie header and some HTML content.
- Visit the page in Firefox and observe the HTML renders.
- Check the Storage tab in developer tools to see the cookie has been set.
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.
A website can send a special response type that lets it update parts of the page. Firefox also lets each part set cookies, which are small pieces of data stored by the browser. This means if an attacker can control the response, they can set cookies on the site's domain, which might let them do things like log the user into an attacker-controlled account.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.