Bypassing Web Cache Poisoning Countermeasures
Cloudflare's mitigations against web cache poisoning, which added headers like X-Forwarded-Host to the cache key and blocked XSS characters, could be bypassed by sending duplicate headers. An attacker could poison the cache and serve malicious content to other users.
Published on portswigger.net
Following my presentation and whitepaper on Web Cache Poisoning last month, various companies have deployed defences in an attempt to mitigate cache poisoning attacks. In this post I’ll take a look at some common weaknesses that can be used to bypass them.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the cache implementation only considered the first occurrence of a header when building the cache key, while the backend concatenated all occurrences, creating a mismatch.
What the attacker needed
Target uses Cloudflare with the mitigation; attacker can send HTTP requests
The fix
The cache key bypass was patched by Cloudflare after being reported.
How it was found
- Send a request with a duplicate X-Forwarded-Host header: the first instance matches the Host header, the second contains the payload.
- The cache key is computed using only the first header value, so it matches the legitimate cache key.
- The backend concatenates both header values, including the payload, and the response is cached under the legitimate key.
- Other users requesting the same resource receive the poisoned response.
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 write-up has not been written yet. The Original tab links to the source.
Web cache poisoning is when an attacker tricks a website's cache into storing a malicious response, so other visitors get that response. Cloudflare tried to stop this by including certain headers in the cache key (the identifier for stored responses) and blocking dangerous characters, but the attacker found a way around these defences by sending the same header twice.
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.