Web Cache Poisoning Explained: The Bug That Serves Your Poison to Everyone


Imagine you visit a website and see someone else’s malicious script running on the page. You didn’t click anything wrong. The site didn’t get hacked. What happened is that a cache — the middleman between you and the website — served you a poisoned copy of the page.

That’s web cache poisoning, and it’s one of the most impactful bugs in modern web security. One crafted request poisons the cache, and every visitor after that gets the attacker’s payload.

How Web Caching Works

To make websites fast, companies put caches (CDNs like Cloudflare, or reverse proxies like Varnish) in front of their servers. When you request a page, the cache stores a copy. The next visitor gets the stored copy instead of bothering the server.

Caches decide what to store using cache keys — usually the URL and a few headers. The problem starts when the cache and the origin server disagree about which parts of a request matter.

How Poisoning Works

The classic attack uses an unkeyed header — a header the server reads but the cache ignores. Here’s the recipe:

  1. The attacker sends a request with a malicious value in an unkeyed header, like X-Forwarded-Host: evil.com.
  2. The origin server uses that header to build the page — maybe it puts the host into a link or a redirect.
  3. The cache stores the poisoned page under the normal URL, because the header wasn’t part of the cache key.
  4. Every visitor who requests that URL gets the poisoned page — with the attacker’s content inside it.

One request. Thousands of victims. That’s the power of cache poisoning.

What Attackers Achieve With It

  • Stored XSS at scale — the poisoned page runs JavaScript in every visitor’s browser, stealing sessions and credentials.
  • Redirects to phishing pages — the cache serves a redirect to the attacker’s fake login page.
  • Defacement — the poisoned page replaces real content for everyone.
  • Denial of service — poison the cache with error pages and the site looks down for every visitor.

How to Test for It (Legally, In Scope)

Cache poisoning is a high-value bug bounty target. Here’s the safe, methodical approach — only on targets with an active bug bounty program or written permission:

  1. Find the cache. Send two identical requests and compare the response headers. Look for headers like X-Cache: HIT or CF-Cache-Status: HIT — that tells you a cache is in front.
  2. Probe unkeyed headers. Try headers like X-Forwarded-Host, X-Forwarded-Scheme, X-Host and X-Forwarded-Port with a unique marker value (for example, X-Forwarded-Host: test123.example.com). If your marker appears in the response, the server reflects it.
  3. Check if it caches. Send the same poisoned request, then send a clean request for the same URL. If the clean request returns your marker, the cache stored it — you’ve found cache poisoning.
  4. Use a cache-buster. Add a random query parameter (like ?cb=12345) to force a fresh cache entry for each test, so you don’t pollute the real cache with junk.

How Developers Prevent It

  • Never reflect untrusted headers into responses — especially X-Forwarded-Host and similar.
  • Include all security-relevant headers in the cache key, or strip unkeyed headers at the edge.
  • Disable caching for responses that contain user input, using Cache-Control: no-store.
  • Validate the Host header against an allowlist of your real domains.

Why It Pays Well

Cache poisoning bugs are rare, hard to find, and devastating when they work — which is why bug bounty programs pay generously for them. The researcher who popularized the technique, James Kettle of PortSwigger, showed that a single poisoned response could hit millions of users.

Learn how caches work, practice on PortSwigger’s free Web Security Academy labs, and only test targets you’re authorized to test. Only test systems you own or have written permission to test.

One request. Every visitor. That’s why cache poisoning matters.

Comments

Popular Posts