Web cache poisoning via an unkeyed query parameter

2 min read Easy Portswigger
Web cache poisoning
Contents

On this page

The lab

here is how portswigger describes it

This lab is vulnerable to web cache poisoning because it excludes a certain parameter from the cache key. A user regularly visits this site's home page using Chrome. To solve the lab, poison the cache with a response that executes alert(1) in the victim's browser.

a close cousin of the unkeyed query string lab, but the detail is sharper here. the whole query string is keyed, change it and you get a cache miss, so you cannot just poison through any parameter. the cache excludes one specific parameter from the key while the app still reflects it into the page. so the job is to find that one unkeyed parameter, then inject through it, because only it lets us change the response without changing the cache key.

why one parameter is the hole#

normally when the query string is part of the cache key, two requests with different parameters are different entries and nothing we inject through the query string ever lands on the victim's clean key. this app breaks that for a single parameter, it strips that one parameter out before building the key, so a request carrying it keys the same as a request without it. the application still reads and reflects it, so it changes the response while the cache sees the same url. find that parameter and it behaves exactly like the unkeyed query string case, inject through it, let the poisoned response cache under the clean key, and every visitor gets our payload.

Step 1 - Confirm the query string is keyed#

we load the home page, and it works as a cache oracle, X-Cache tells us hit or miss. we change the query string and get a cache miss every time, which means the query string is part of the cache key. we also notice the query string is reflected in the response. so there is a reflection to abuse, but we cannot poison the shared entry through just any parameter because they are all keyed.

111

Step 2 - Find the excluded parameter with Param Miner#

the lab excludes one specific parameter from the key, so we brute force parameter names with Param Miner's Guess GET parameters feature. it reports that the application supports the utm_content parameter.

222

Step 3 - Confirm utm_content is unkeyed#

we add utm_content to the query string and check that we still get a cache hit, meaning it is not part of the key. we keep sending until we get a miss so the app generates a fresh response, and we observe that this unkeyed parameter is reflected in the response along with the rest of the query string.

333

Step 4 - inject the XSS payload through utm_content#

we send a request with a utm_content value that breaks out of the reflected string and injects script:

http
GET /?utm_content='/><script>alert(1)</script>
444

the '/> closes the attribute and tag the value lands in, and the <script>alert(1)</script> runs. because utm_content is excluded from the key, this poisoned response is stored under the same entry a plain home page request would reach.

Step 5 - poison and solve#

once our payload is cached, we remove the utm_content parameter, right-click the request and choose Copy URL. we open that clean url in the browser and the alert() fires on load.

555

the regular Chrome visitor hits the same cached entry and runs our payload, which solves the lab.

with this, the lab is solved!