The lab
here is how portswigger describes it
To solve the lab, find the API key for the user carlos. You can log in to your own account using the following credentials:
wiener:peter. We have provided a list of possible delimiter characters to help you solve the lab: Web cache deception lab delimiter list.
the new pieces in this lab#
this is the mirror image of the origin-normalization lab, and the hardest WCD so far because the winning payload stacks two discrepancies. it's worth being precise about who normalizes what.
- last lab: the origin resolved the dot-segment and the cache didn't. here it's reversed, the cache decodes and resolves the dot-segment, while the origin does not. so
/resources/..%2fmy-accountwon't work (the origin wouldn't resolve it to/my-account). we need the opposite construction. - because the cache resolves dot-segments, we can make a URL that the cache collapses down to
/resources(so it matches the cached static-directory rule) while the origin still sees and serves/my-account. - to keep the origin on
/my-account, we use a path delimiter the origin honours but the cache does not, exactly the delimiter-discrepancy idea from two labs ago. the origin truncates the path at that delimiter (→/my-account), while the cache treats the delimiter as a literal character and keeps reading, so it still sees (and resolves) the rest of the path. - the subtlety with
#: the browser treats a raw#as the start of a fragment and strips everything after it before sending the request, so a literal#never reaches the cache and is useless in an exploit. but the URL-encoded form%23is sent as data, the browser forwards it, the origin decodes it back to#and uses it as a delimiter, and the cache keeps it literal. that's why%23works where#cannot. the plan: find the origin's delimiters (#,?,%23,%3f), find that the cache resolves dot-segments and caches/resources, then combine a cache-resolvable dot-segment with the%23delimiter so the cache normalizes the path to/resources(cached) while the origin truncates at%23to/my-account(private page).
why the stacked discrepancy leaks the API key#
the exploit path is /my-account%23%2f%2e%2e%2fresources, which decodes to /my-account#/../resources. the two components read it completely differently:
- the origin treats
%23(#) as a path delimiter, so it stops reading at the#and sees just/my-account, returning the logged-in user's private account page. it never looks at the/../resourcestail. - the cache does not treat
%23as a delimiter, so it keeps the whole path, and it does decode and resolve dot-segments. resolving/my-account#/../resources, the..climbs up over themy-account#segment, leaving/resources. the cache now believes the request is for/resources, which matches its static-directory cache rule, so it caches the response. so one request is "the private account page" to the origin and "a file under /resources" to the cache. the cache stores carlos's authenticated response under a key anyone can request.?fails because the cache also treats?as a delimiter, it would truncate before ever resolving the dot-segment to/resources.%23is the one delimiter the origin honours but the cache ignores, and stacking it with the cache's dot-segment resolution is what lands the account page in the/resourcescache.
Step 1 - confirm no path abstraction#
we log in as wiener:peter; the response holds our API key. in Proxy > HTTP history we send GET /my-account to Repeater and change the path to /my-account/abc, which returns 404 Not Found. so the origin doesn't abstract the path to /my-account.

Step 2 - build a reference response#
we change the path to /my-accountabc and send, 404 Not Found with no caching. this is our "not a delimiter" reference.

Step 3 - brute-force the origin's delimiters#
we send the request to Intruder, Sniper, payload position after /my-account:
/my-account§§abc
we load the delimiter list and deselect "URL-encode these characters", then start the attack. sorting by status, the #, ?, %23, and %3f characters return 200 with our API key, these are the origin's delimiters. we ignore #: the victim's browser treats a raw # as a fragment and strips it before the request reaches the cache, so it can't be used in an exploit.

Step 4 - rule out a simple delimiter+extension exploit#
in Repeater we test a delimiter plus a static extension, /my-account?abc.js, and send, no evidence of caching. we repeat with %23 and %3f; none show caching. so there's no .js extension rule to abuse this way; we pivot to normalization.

Step 5 - confirm the origin does NOT resolve dot-segments#
we prepend an arbitrary directory and an encoded dot-segment:
/aaa/..%2fmy-account
this returns 404, so the origin does not decode/resolve the dot-segment to /my-account. (the opposite of the previous lab, this time the origin leaves the path alone.)

Step 6 - confirm the cache resolves dot-segments and caches /resources#
in Proxy > HTTP history we see static resources share the /resources prefix and responses there are cached. we send a /resources request to Repeater and prepend an encoded dot-segment plus an arbitrary directory:
/aaa/..%2fresources/YOUR-RESOURCE
the 404 response shows X-Cache: miss; resending flips it to hit. so the cache decoded and resolved ..%2f (collapsing /aaa/../resources → /resources) and cached it under the /resources rule. to confirm it's that rule, we test /resources/..%2fYOUR-RESOURCE, which now shows no caching, because the cache resolves it away from /resources, proving the cache both resolves dot-segments and keys on the /resources prefix.

Step 7 - build the stacked exploit#
in the /aaa/..%2fmy-account tab we construct the exploit using a delimiter. first with ?:
/my-account?%2f%2e%2e%2fresources
this returns 200 with our API key but no caching, because the cache also treats ? as a delimiter and truncates before resolving. we repeat with %23:
/my-account%23%2f%2e%2e%2fresources
this returns 200 with our API key and X-Cache: miss; resending flips to hit. %23 is the delimiter the origin honours but the cache ignores, so the cache resolves the tail to /resources and caches it. this is our exploit.

Step 8 - craft the exploit#
we go to the exploit server and, in the Body, redirect carlos to the malicious URL with an arbitrary query parameter as a cache buster:
<script>document.location="https://YOUR-LAB-ID.web-security-academy.net/my-account%23%2f%2e%2e%2fresources?wcd"</script>

Step 9 - retrieve carlos's cached response#
we deliver the exploit, then visit the same URL:
https://YOUR-LAB-ID.web-security-academy.net/my-account%23%2f%2e%2e%2fresources?wcd
the cached response includes carlos's API key.

Step 10 - submit the key#
we copy and submit carlos's API key.

with this, the lab is solved!
