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. There is also inconsistent parameter parsing between the cache and the back-end. A user regularly visits this site's home page using Chrome. To solve the lab, use the parameter cloaking technique to poison the cache with a response that executes
alert(1)in the victim's browser.
this one layers two bugs. one parameter, utm_content, is excluded from the cache key as in the previous lab. on top of that the cache and the back-end disagree about how to split parameters, the cache splits only on & while the back-end also splits on ;. so if we hide a parameter behind a semicolon inside utm_content, the cache sees one harmless excluded parameter but the back-end sees two, and the smuggled one reaches the application unkeyed. we use that to override a jsonp callback name with our payload, cloaked from the cache the whole way.
what is a cache key#
when a response is cached the cache needs a way to decide, for a later request, whether it can reuse a stored copy. it computes a cache key from selected parts of the request, typically the path and some headers, and sometimes the query string. if a new request produces a key that matches a stored entry, the cache serves that saved response without asking the back-end. the key is the identity of the entry. anything left out of the key is invisible to the cache's matching but still seen by the application, and that mismatch between what the cache keys on and what the app actually acts on is the entire family of web cache poisoning bugs, parameter cloaking included.
Step 1 - Confirm the excluded parameter#
as in the unkeyed query parameter lab, we identify that utm_content is supported and that it is excluded from the cache key, add it and the response still comes from cache. that gives us one parameter the cache ignores but the app still reads.

Step 2 - Find the parsing mismatch#
we notice that if we append another parameter to utm_content using a semicolon, the cache treats the whole thing as one parameter. so utm_content=a;foo=bar is a single excluded parameter to the cache, but the back-end splits on ; and sees a separate foo=bar. that means anything we smuggle after a semicolon rides along unkeyed. with Param Miner loaded we can also confirm this automatically via right-click, Bulk scan > Rails parameter cloaking scan.

Step 3 - Find the jsonp callback to hijack#
every page imports the script /js/geolocate.js, which executes the callback setCountryCookie(). we send GET /js/geolocate.js?callback=setCountryCookie to Repeater and see that the callback parameter controls the name of the function called on the returned data, so whatever we put there is written into the response as a function call.

but callback on its own is keyed, change it and the cache keys a different entry, so we cannot poison other users with it directly. we need to change the callback without changing the cache key.
Step 4 - Cloak the callback override#
we study the cache behaviour. adding duplicate callback parameters shows only the final one is reflected, but both are still keyed, so that does not help. the trick is to append the second callback to utm_content with a semicolon:
GET /js/geolocate.js?callback=setCountryCookie&utm_content=foo;callback=alert(1)
the cache sees callback=setCountryCookie (keyed, normal) and utm_content=foo;callback=alert(1) (one excluded parameter). the back-end splits the semicolon, reads the smuggled callback=alert(1), and that overwrites the reflected function name, all while the cache key stays that of the innocent request.

Step 5 - inject the payload#
we send the request with alert(1) as the cloaked callback so the script the page imports becomes a call to alert(1):
GET /js/geolocate.js?callback=setCountryCookie&utm_content=foo;callback=alert(1)

Step 6 - poison and solve#
we replay until that poisoned geolocate.js response is cached, then load the home page in the browser. the page imports the now-poisoned script, which runs alert(1).


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