Exploiting path delimiters for web cache deception

4 min read Easy Portswigger
Web cache deception
Contents

On this page

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#

same goal as the path-mapping lab, steal carlos's cached account page, but the discrepancy we exploit is different. last time the origin abstracted an extra path segment (/my-account/abc → /my-account). here it does not, so we need a different way to bolt a .js extension onto the account page without changing which page the origin serves.

  • a path delimiter is a character that marks where the meaningful part of the path ends. different servers treat different characters as delimiters. for example, many servers stop reading the "route" at ; (a matrix-parameter separator) or ? (the query-string separator), so /my-account;abc and /my-account?abc both still route to /my-account, everything after the delimiter is ignored for routing.
  • the key discrepancy is that the origin and the cache may use different delimiter sets. if the origin treats ; as a delimiter (so /my-account;abc.js routes to /my-account and returns the account page) but the cache does not (so the cache sees the whole string /my-account;abc.js, ending in .js, and caches it as a static file), we have our deception. the opposite case, a character both treat as a delimiter, is useless, because then the cache also truncates and never sees the .js.
  • the method for finding delimiters is a Sniper brute-force: inject each candidate character after /my-account and watch which ones make the origin return the account page (200 + API key) instead of 404. those are the origin's delimiters. then we test each against the cache to find one the cache does not treat as a delimiter. the plan: brute-force the delimiter characters (finding ; and ? route to /my-account), determine that the cache ignores ; as a delimiter but honours ?, so /my-account;abc.js is cached as .js while still returning the account page, then lure carlos to that URL and read his cached API key.

why the delimiter mismatch leaks the API key#

the flaw is that the cache and the origin disagree about where the path ends. to the origin, ; is a delimiter: it reads /my-account;wcd.js as /my-account plus some trailing matrix-parameter junk, and returns the logged-in user's private account page. to the cache, ; is not a delimiter: it takes the full literal string /my-account;wcd.js, sees it ends in .js, and applies its "cache static files" rule. so the origin produces dynamic per-user data while the cache files it away as a public script. ? is no good here because the cache also treats it as a delimiter, it would truncate to /my-account and never see a .js to cache. the whole exploit hinges on finding a delimiter the origin honours but the cache ignores, that single-character disagreement is enough to cache carlos's authenticated response under a URL anyone can fetch.

Step 1 - confirm the API key is in the response#

we log in as wiener:peter and notice the response contains our API key, so /my-account returns per-user data.

11

Step 2 - check whether the origin abstracts a path segment#

in Proxy > HTTP history we send the GET /my-account request to Repeater and add an arbitrary segment, /my-account/abc, then send. we get a 404 Not Found with no caching, so unlike the previous lab, the origin does not abstract the path to /my-account. an extra segment won't work; we need a delimiter.

22

Step 3 - build a reference response#

we remove the segment and instead append an arbitrary string directly to the path, /my-accountabc, and send. this also returns 404 Not Found, uncached. we'll use this as our reference for "not a delimiter", any candidate character that behaves like this isn't a delimiter.

33

Step 4 - brute-force the origin's delimiters#

we send the /my-accountabc request to Intruder. with a Sniper attack we add a payload position between /my-account and abc:

/my-account§§abc

in Payloads we load the candidate delimiter characters. crucially, under Payload encoding we deselect "URL-encode these characters" so the raw characters are sent as-is. we start the attack and sort results by Status code. the ; and ? characters return 200 with our API key; everything else returns 404. so the origin treats ; and ? as path delimiters, both route to /my-account.

44

Step 5 - find a delimiter the cache ignores#

now we test those delimiters against the cache. in Repeater we build /my-account?abc.js (using ?) and send, no evidence of caching, which suggests the cache also treats ? as a delimiter (it truncates to /my-account and never sees the .js). we repeat with ;: /my-account;abc.js returns X-Cache: miss. resending it changes X-Cache to hit. so the cache does not treat ; as a delimiter, it caches the whole path as a .js static file, while the origin still returned the account page. ; is our exploit delimiter.

55

Step 6 - craft the exploit#

we go to the exploit server and, in the Body, redirect carlos to a malicious ;-delimited .js URL, changing the arbitrary string (to wcd) so the cache key is unique and carlos caches his account details rather than receiving our earlier cached response:

html
<script>document.location="https://YOUR-LAB-ID.web-security-academy.net/my-account;wcd.js"</script>
66

Step 7 - retrieve carlos's cached response#

we deliver the exploit, then visit the same URL:

https://YOUR-LAB-ID.web-security-academy.net/my-account;wcd.js

the cached response includes carlos's API key.

77

Step 8 - submit the key#

we copy and submit carlos's API key.

88

with this, the lab is solved!