Issue
A web cache stores a copy of an HTTP response so it can serve later requests without contacting the application server. Caches may run in a browser, reverse proxy, content delivery network (CDN), or application. A cache key is the set of request details a cache uses to decide whether two requests can share a stored response. The HTTP caching standard requires caches to consider the target URI and request method when reusing a response; response headers such as Vary can require additional request headers to match. Actual cache configurations may add their own rules. RFC 9111
Web cache poisoning occurs when an input changes a response but the cache does not distinguish requests that use different values of that input. If the resulting response is stored and reused, later visitors whose requests match the cache key may receive the changed response. For example, an application might use X-Forwarded-Host to generate a link, while a CDN’s cache key does not include that header. An attacker could then try to make the application produce a response containing a value that the cache serves to other visitors. OWASP Web Cache Security Cheat Sheet PortSwigger Web Security Academy
Common causes include:
- Unkeyed inputs: The application uses a request header, cookie, or query parameter to change a response, but the cache key does not account for it.
- Incorrect variation rules: A response varies by a request header, but the cache does not distinguish the variants—for example, because Vary is missing or the cache configuration does not apply it as expected.
- Untrusted host or forwarding values: The application uses client-controlled Host, Forwarded, or X-Forwarded-Host values to generate links or other response content.
- Incomplete or inconsistent cache keys: The cache and application handle query parameters, URL normalization, ports, or routing differently, so distinct requests may map to the same cache entry.
- Mismatched cache policies: The origin, CDN, and proxy disagree about which responses or request variants can be stored and reused.
These conditions are indicators to investigate; they do not confirm a vulnerability until testing shows that an affected response is cached and reused across requests. OWASP Web Cache Security Cheat Sheet
Three conditions are needed for this form of poisoning:
- The attacker can influence an input that changes the response.
- The cache stores that response.
- The cache may reuse it for requests that do not carry the same input value.
A reflected value or an unexpected response alone does not establish all three conditions. Cache poisoning is also different from web cache deception, where a cache is tricked into storing a private response under a URL it treats as cacheable.
Examples
Request with a marker:
GET /help HTTP/1.1Host: app.exampleX-Forwarded-Host: marker-7f2.example
Illustrative first response:
HTTP/1.1 200 OKCache-Control: public, max-age=60Content-Type: text/html <a href="https://marker-7f2.example/help">Help</a>
The marker appearing in the response shows that the application used the supplied header. It does not prove cache poisoning.
Illustrative later request without the marker:
GET /help HTTP/1.1Host: app.example
Illustrative response from a test cache:
HTTP/1.1 200 OKAge: 4X-Cache: HITContent-Type: text/html <a href="https://marker-7f2.example/help">Help</a>
If the cache’s logs or configuration confirm that this response was reused for the second request, the test supports a finding that the cache shares responses across requests that differ in X-Forwarded-Host. X-Cache is illustrative and vendor-specific; the response should be validated using the actual cache’s logging or diagnostics. This example does not establish any further impact, such as script execution or account compromise.
Impact
The impact depends on what the changed response does, which visitors share the affected cache entry, and how long the entry remains usable. A poisoned page might show incorrect content, send visitors to an unintended destination, or deliver a client-side attack if the response contains executable content in a context where a browser will run it. Those consequences require evidence of the specific behavior; finding a reflected header does not by itself prove script execution, data exposure, or account compromise. PortSwigger Web Security Academy
A private or personalized response being served to another user is a serious cache isolation problem, but it is not the same issue as poisoning a public response with attacker-controlled content. Test and report the observed behavior separately.
Testing
1. Confirm whether an altered response reaches another request
On a controlled cache entry, send a request with one changed input that appears in the response. Fetch the same cache key without that input and inspect cache diagnostics and body.
Example: A changed link followed by a clean cache hit containing the same marker supports cross-request reuse. Reflection in the first response alone does not.
GET /help?test=case1 HTTP/1.1
Host: app.example.test
X-Forwarded-Host: marker.example.test
2. Find inputs that change cacheable responses
Compare a normal request with one changed header, cookie, or query value at a time. Record the response, cache status, and which values form the cache key.
Example: A forwarding header may change a generated link. The cache must also store and reuse that changed response for poisoning to occur.
GET /help?test=case2 HTTP/1.1
Host: app.example.test
X-Forwarded-Host: marker.example.test
3. Compare cache rules across layers
Inspect Cache-Control, Vary, cache configuration, and any CDN overrides. Check personalized pages separately from attacker-influenced public responses.
Example: Browser cache and shared CDN cache are different layers. Use cache logs or provider diagnostics to identify the layer involved.
Common false positives: A changed origin response may not be cached. A browser’s local cache may make a result appear repeatable without affecting other users. A cache-busting parameter may change the cache key and prevent the test from exercising the normal entry. Conversely, browser developer tools that disable the browser cache do not necessarily bypass a CDN or reverse proxy. Distinguish these layers before concluding that a shared cache is involved.
Mitigation
Primary fixes
- Use a complete cache key. Include every request value that can legitimately change a shared response, or do not share that response. Configure this at the cache layer and verify the deployed rule. Vary can identify request headers that affect representation selection under HTTP caching rules, but check that the specific CDN or proxy honors it as expected. RFC 9111
- Do not trust client-supplied forwarding headers. At the trusted edge, remove or replace headers such as Forwarded and X-Forwarded-Host. Configure the application to accept proxy headers only from trusted proxies. Build canonical links from a configured public origin rather than arbitrary request values.
- Keep personalized and sensitive responses out of shared caches. Set an explicit policy for each route. Use
Cache-Control: privatewhen a response may be stored in a user’s private cache but must not be stored by a shared cache; use no-store when it must not be stored. Ensure CDN rules do not override the intended policy. RFC 9111 OWASP Web Cache Security Cheat Sheet - Remove unnecessary response variation. If the application does not need to vary a response based on a header or cookie, stop using that input for response generation.
Additional defensive measures
- Document cache behavior for each route and keep origin, proxy, and CDN policies aligned.
- Restrict public caching to responses designed to be shared.
- Log cache decisions and key components where the platform supports it, while avoiding sensitive values in logs.
- After changing a cache policy, purge affected entries. Retest with the marker method and a clean second request to confirm that the changed response is no longer shared incorrectly.