The lab
here is how portswigger describes it
This lab is vulnerable to web cache poisoning because the query string is unkeyed. A user regularly visits this site's home page using Chrome. To solve the lab, poison the home page with a response that executes
alert(1)in the victim's browser.
this time the unsafe input is the query string itself, and the cache does not key on it. the home page reflects a query parameter into the response, so we can inject an xss payload through a parameter, and because the query string is unkeyed the cache files that poisoned response under the plain home page key, the one a victim reaches with no query string at all. the twist is testing it without wrecking the real entry, since the query string we would normally cache-bust with is the very thing being ignored, so we need a different buster.
why the unkeyed query string is the hole#
the cache key is built from the keyed parts of the request, and here the query string is left out of it. that means / and /?anything=here resolve to the same cache entry, so a response generated for a request carrying our malicious parameter is stored under the bare home page key. the application still reads the query string and reflects it into the page, so it changes the response while the cache treats it as the same url. that gap is the whole attack, inject through the unkeyed query string, let the poisoned response get cached under the clean key, and every visitor hitting the plain home page is served our payload.
Step 1 - Identify the cache oracle#
we load the home page, then in Proxy > HTTP history we find the GET request for it. it behaves as a cache oracle, its response tells us through X-Cache whether we are hitting the cache. we send the request to Repeater to work on it.

Step 2 - Confirm the query string is unkeyed and find a buster#
we add arbitrary query parameters and resend. we still get X-Cache: hit even though the parameters changed, which proves the query string is not part of the cache key. that is useful for the attack but awkward for testing, we cannot cache-bust with the query string if the cache ignores it.
so we use the Origin header as a cache buster instead, a keyed header we can vary to give our experiments their own cache entry without touching the real home page:
Origin: https://anything-unique.example

Step 3 - Inject the XSS payload through a parameter#
we add a parameter whose value breaks out of the reflected string and injects script:
GET /?evil='/><script>alert(1)</script>

the '/> closes the attribute and tag our value lands in, and the <script>alert(1)</script> that follows runs. we replay until we see our payload reflected in the response and X-Cache: hit, meaning our crafted response is now cached under our Origin-busted key.
Step 4 - Prove it serves to a plain request#
to simulate the victim we remove the query string from the request but keep the same Origin cache buster, and send it again. we still get the cached response containing our payload, which confirms the stored copy is served to a request with no query string, exactly how a real visitor arrives.

Step 5 - Poison the real cache and solve#
now we remove the cache-buster Origin header and add the payload back to the query string, so we are poisoning the real shared home page entry. we replay until the clean home page key holds our poisoned response.
we confirm by loading the home page in the browser, with no query string, and the alert(1) pops.

the regular Chrome visitor hits the same cached entry and runs our payload, which solves the lab.
with this, the lab is solved!
