Web Cache Poisoning
A shared cache stores a response that was shaped by a request input it does not include in its cache key, so an attacker's harmful response is served to other users.
| Severity | High |
| CVSS 3.1 | 8 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:N Open in the calculator |
| CVSS 4.0 | 7.1 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:H/VA:N/SC:H/SI:H/SA:N Open in the calculator |
| CWE | CWE-349: Acceptance of Extraneous Untrusted Data With Trusted Data |
| MITRE ATT&CK | T1189 Drive-by Compromise |
| Category | Input Validation |
Description
The application sits behind a shared cache, such as a content delivery network, reverse proxy or framework cache, which decides whether two requests are the same by a cache key, usually the method, host, path and query string. The application's responses, however, are also influenced by inputs outside that key, known as unkeyed inputs: headers such as X-Forwarded-Host or X-Forwarded-Scheme, query parameters excluded from the key, cookies or a request body.
An attacker sends a request in which an unkeyed input makes the response harmful, for example by pointing a script import at their own server or by reflecting a cross-site scripting payload, and the cache stores that response and serves it to everyone who requests the same key while the entry remains cached, without those users following any link. Depending on the input involved, this can run script in the browsers of all visitors, redirect them to another site, or make a page unusable by caching an error, which is a form of denial of service. The attacker can repeat the request to keep the entry poisoned. Success depends on the cache's timing and key behaviour, which the attacker must study first.
The weakness typically shows itself on a test when an added header or parameter changes the response while cache headers such as Age or X-Cache show that it is being stored. Tools such as the Param Miner extension for Burp Suite find unkeyed inputs by guessing them. Tests should include a unique cache-busting parameter so that real users are not served a test response. Burp Suite reports confirmed cases as web cache poisoning.
Remediation
Make sure the cache key covers everything that can change a cacheable response:
- Do not let any request input outside the cache key change a cacheable response. Remove or overwrite forwarding headers such as
X-Forwarded-Hostat the edge unless they are set by the organisation's own proxy, and build absolute URLs from configuration. - Include every input that legitimately changes a response in the cache key, using the
Varyheader for request headers, or reject that input on cacheable routes. - Cache only responses that are meant to be shared, and set
Cache-Control: no-storeorprivateon dynamic and personalised responses. Avoid caching error responses, or cache them only briefly. - Apply the same URL normalisation and parameter handling at the cache and at the origin, and reject request bodies on GET routes.
- After fixing, purge every affected cache layer.
Confirm the fix by repeating the original requests with a cache buster and checking that the unkeyed inputs no longer change the response.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.