Skip to content
Cache bugs Write-up Intermediate

Web Cache Poisoning

The web cache used an unkeyed header (x-forwarded-host) that was reflected in the page, allowing an attacker to inject JavaScript and poison the cache so that other users received the malicious script.

medium.com

Published on medium.com

In this blog we will be learning about Cache, caching headers and the basics of Web Cache Poisoning.

Ams._.Ghimire, on medium.com

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 key did not include the x-forwarded-host header, and the application reflected that header's value into the page without sanitisation.

Impact

An attacker could inject JavaScript into the cached page, which would then execute for any user who visited the page before the cache expired.

What the attacker needed

Ability to send requests with custom headers; cache must be enabled and store responses; unkeyed header reflected in response

The fix

The cache key should be normalised to include all headers that affect the response, and cache-control headers should prevent caching of sensitive data.

How it was found

  1. Check the application's cache headers and confirm caching is active.
  2. Use a tool to find unkeyed headers that are reflected in the response.
  3. Inject a test value into the unkeyed header and observe where it appears.
  4. Craft a payload that breaks out of the script tag and injects JavaScript.
  5. Send the request repeatedly until the cache stores the malicious response.
  6. Open the page in a private window to confirm the injected script executes.

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.

A web cache stores copies of web pages to serve them faster. If a cache ignores a header when deciding which stored page to return, an attacker can put malicious content in that header and have it saved in the cache, so other visitors get the attacker's version of the page.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Web cache poisoning and deception

The lesson behind this report.

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.