Browser cache poisoning attack using fetch() with different headers
The browser's private cache is shared between Fetch requests and normal navigation, but the cache key does not include request headers that can vary the response. An attacker can use Fetch to pre-load a poisoned response into the cache, then force the victim to navigate to the page, activating the attack.
- Fixed in 11 months
- Paid in 12 months
- Disclosed after 11 months
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0
Steps to reproduce:
TL;DR
If the right set of circumstances are present, Fetch can be used to pre-load the browser private cache, and poison normal navigation. Using this approach, a range of attacks that were previously thought to be unexploitable, can be unlocked and made practical. Hurrah!
Blah Blah Blah
The reason that this works is because the browser shares the private cache between Fetch and normal navigation, with the cache key being based upon the URI and originating context. However, because Fetch is able to add headers to the request that can vary the response (but which are not included in the cache key), an attacker can pre-request resources to poison the private cache, then force the browser to navigate to the page, which activates the attack.
To make this work requires two things:
-
The Fetch request and response must be cacheable under normal circumstances by the browser. Typically, a GET method, and the response must be implicitly cacheable (301/308 status code, and last-modified header), or explicitly cacheable (cache-control, pragma and expires headers).
-
The target endpoint must pass a pre-flight check, as adding additional headers to a Fetch request requires CORS.
As an interesting observation, the response does not always have to be made available to Fetch for the browser cache to be updated. For example, if the pre-flight passes, but the actual response does not have an access-control-allow-origin header, then it will be blocked due to CORS. But even so, the cache will sometimes still be updated successfully.
Recommendations
It is recommended that additional information is added to the cache key, so that requests made by Fetch and the normal navigation are separated.
PoC
The following PoC links launch same-origin, same-site and cross-origin tests, either directly or from within an iframe data URI (to force a null origin).
301 status code (direct)
- cross-site: https://p1.scarlet.ae/ff229a50-9266-4741-a478-ff91383525fa
- same-site: https://p1.smelter.org/ff229a50-9266-4741-a478-ff91383525fa
- same-origin: https://p2.smelter.org/ff229a50-9266-4741-a478-ff91383525fa
200 status code (direct)
- cross-site: https://p1.scarlet.ae/9991460e-55db-49eb-8716-f4c72fd74d0c
- same-site: https://p1.smelter.org/9991460e-55db-49eb-8716-f4c72fd74d0c
- same-origin: https://p2.smelter.org/9991460e-55db-49eb-8716-f4c72fd74d0c
301 status code (iframe)
- cross-site: https://p1.scarlet.ae/17a031ba-cd6e-4cc0-af06-4c3f80354731
- same-site: https://p1.smelter.org/17a031ba-cd6e-4cc0-af06-4c3f80354731
- same-origin: https://p2.smelter.org/17a031ba-cd6e-4cc0-af06-4c3f80354731
200 status code (iframe)
- cross-site: https://p1.scarlet.ae/e5b1e318-d679-4b47-b113-744cc97bcacf
- same-site: https://p1.smelter.org/e5b1e318-d679-4b47-b113-744cc97bcacf
- same-origin: https://p2.smelter.org/e5b1e318-d679-4b47-b113-744cc97bcacf
Actual results:
as above
Expected results:
as above
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
The browser's cache key does not include request headers that can change the response, allowing Fetch requests to poison the cache for normal navigation.
Impact
An attacker could poison the browser cache to serve malicious content, potentially enabling attacks previously thought unexploitable, but only if the response is cacheable and the request passes CORS pre-flight.
What the attacker needed
Response must be cacheable; request must pass CORS pre-flight
The fix
The cache key should be extended to include request headers that can vary the response, separating Fetch requests from normal navigation.
How it was found
- Use Fetch to send a request with headers that cause a malicious response, which gets cached.
- Force the browser to navigate to the same URL, which loads the poisoned response from the cache.
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 web browser keeps a local copy (cache) of pages to load them faster. This report shows that a script can trick the browser into saving a malicious version of a page, which is then shown when the user visits that page normally.
What is Cache bugs?
A cache and the origin disagree about a request, so a poisoned response is served to everyone or a private page is stored as public.