portswigger-all-labs

Complete PortSwigger Web Security Academy Lab Writeups Detailed, categorized solutions for every lab — from APPRENTICE to EXPERT — covering all 30 vulnerability types.

View on GitHub

Web Cache Poisoning

What is Web Cache Poisoning?

Web cache poisoning is an advanced attack technique that allows an attacker to exploit caching behavior so that a harmful HTTP response is served to other users. The attack unfolds in two primary phases:

  1. Elicit a harmful response from the origin server using manipulated input.
  2. Get that response cached so that it’s served to other users with equivalent cache keys.

This technique can lead to serious exploits such as:


Understanding Web Cache Behavior

Types of Caches:

Web cache poisoning targets application-level caches, not browser or DNS caches.

How Does a Web Cache Work?

A web cache stores server responses to reduce the load and latency of web applications. When a request is made:

Cache Keys

Cache keys determine which responses get reused. They usually include:

Unkeyed inputs are request components not included in the cache key. These become the attacker’s point of exploitation.


Impact of Cache Poisoning

The severity depends on:

  1. What payload is cached: The more dangerous the payload (e.g. XSS), the higher the impact.
  2. Popularity of the page: A poisoned cache on a high-traffic page amplifies reach.

Even short-lived caches can be re-poisoned continuously, making the effect persistent.


How to Construct a Web Cache Poisoning Attack

1. Identify Unkeyed Inputs

These are often headers like:

Use tools like Burp Suite Param Miner:

Caution: Use cache busters to avoid poisoning real user traffic during tests.

image

2. Elicit a Harmful Response

Once you find an unkeyed input:

3. Get the Response Cached

Trigger conditions that make the response cacheable:

image


Exploiting Web Cache Poisoning

Exploiting Cache Design Flaws

Reflected XSS via Unkeyed Headers

GET /en?region=uk HTTP/1.1
Host: innocent-website.com
X-Forwarded-Host: a."><script>alert(1)</script>

Response:

<meta property="og:image" content="https://a."><script>alert(1)</script>/cms/social.png" />

If cached, this payload is delivered to all users.


Exploiting Unsafe Resource Imports

GET / HTTP/1.1
Host: innocent-website.com
X-Forwarded-Host: evil-user.net

Response:

<script src="https://evil-user.net/static/analytics.js"></script>

This results in arbitrary JS execution for every user who receives the cached page.


image

image

Tools


Additional Resources


Summary

Web cache poisoning is a powerful vulnerability with a wide range of potential impacts. By understanding caching behavior, identifying unkeyed inputs, and crafting harmful yet cacheable responses, attackers can hijack legitimate traffic and distribute malicious content at scale.

Always test responsibly with cache busters.