--- name: hunt-cspt description: Client-Side Prototype Pollution to XSS/CSPT (client-side path traversal) — __proto__ pollution via URL params, gadget exploitation, fetch() path injection, CSPT flagging with regex checks, DOM sinks. Pairs with hunt-prototype-pollution, hunt-xss. --- # CLIENT-SIDE PATH TRAVERSAL (CSPT) & POLLUTION GADGETS — Advanced Guide **Core:** CSPT is a JS-level vulnerability where attacker-controlled input flows into a **local client-side `fetch()`/XHR path**. Unlike SSRF, the request goes out as the *victim user* — so it can hit authenticated, CSRF-protected endpoints. The high-severity exploit is usually "CSPT → authenticated POST request the victim never intended". ## 1. FINDING CSPT SINKS ```javascript // In client JS (bundle*.js), hunt for path construction from attacker input: grep -E "fetch\([a-z_$]|\.open\(['\"]?(GET|POST)['\"],\s*[a-z_$]" bundle.js grep -E "location\.search|URLSearchParams|parseParams" bundle.js // The dangerous shape: fresh URL assembled from a param, no allowlist: fetch(`/api/${route}/inventory`) // route = tracked from URL hash/query fetch(base + path) ``` - The tell: one parameter that changes the *path* rather than a query value. Watch DevTools Network filter for your pollutants (`#test`, `/test`, `../`) — the **request that changes shape** with your input is CSPT-flagged. ## 2. CONFIRMATION (the expensive-looking part done cheap) ```javascript // Pollute and watch: https://target.com/inventory#/page/../../api/users/delete // or query style, per app routing: https://target.com/?page=%2F%2E%2E%2Fadmin%2Fpanel-stealer ``` Checklist on confirmation: 1. The path traversal must be visible in the actual outgoing request (DevTools → Network → "Copy as fetch"). 2. No allowlist/blocklist exists in the JS for that param → note the gadget (which check you'd have expected). 3. For POST-based CSPT: the victim's browser sends **their own cookies** — including CSRF tokens the app auto-attaches — so this defeats same-site defenses. ## 3. FLAGGING GADGETS (regex quickcheck) ```javascript // Generic CSPT flagger — paste in browser console on any SPA page: (() => { const orig = window.fetch; window.fetch = function(input, init) { const url = (typeof input === 'string') ? input : input.url; console.log(`[CSPT-FLAG] fetch: ${url}`); return orig.apply(this, [input, init]); }; const open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(m,u){ console.log(`[CSPT-FLAG] xhr ${m} ${u}`); return open.apply(this,[m,u]); }; })(); // Now click around / change query params; anything whose path echoes your controlled // portion is a live sink. (Remove flagging before shipping results — it changes nothing server-side but keep reports clean.) ``` ## 4. PROTOTYPE POLLUTION → EXPLOITABLE GADGETS (JS) ```http GET /?__proto__[admin]=1 GET /?__proto__[x]=&__proto__[y]=… or JSON-body variant: {"__proto__":{"admin":true}} ``` ```javascript //.polluted → find real world gadget sinks in the app itself function polluted(d){const s=JSON.stringify({...default_stringify(d)});return s} // Known device: // (a) fetch wrapper that merges config: opts = {...defaults, ...userOpts} (prototype method hijack) fetch(String(location)) // (b) client-side template injection: `__proto__.innerHTML` etc. // (c) HTTP header injection gadget: polluted key shows in WebGL shifts; check responses for content-type no-change shapes. ``` **Exploit chain checklist:** - Sink that merges objects (merge(key, custom)) → pollution gain → persists to next application section → escalate to known CSS? → hunt-prototype-pollution for the bible. ## 5. REMEDIATION NOTES (what valid fixes look like) - Allowlist route paths client-side (choice must be after validation, not before). - Array-store for `Object.keys` merges; check `sanitize.js` is only half a fix (delete is not enough for `__proto__`). - State the gadget and payload URLs — a "could-be" without an executed `fetch` is not a CSPT report. ## 6. REPORT AUTH POSITIONS - CSPT: medium usually; becomes high when the polluted path executes an authenticated state-changing call (the app's own guards and CSRF handling are attached to the un-intended request). - Prototype pollution: standalone reports are often LOW until paired with a gadget; collect evidence of *both* internally before filing. - Never say "bypassed CSRF" unless the app's own token was attached to the un-intended call — that is the entire severity argument. ## 7. CSPT vs SERVER-SIDE TRAVERSAL — KNOW WHICH ONE YOU HAVE | | Server-side path traversal | Client-side path traversal (CSPT) | |---|---|---| | `../` is resolved by | The server / filesystem / upstream API | The browser, during URL resolution, before the request leaves | | What you read/reach | Files, internal services, other tenants' data on the server | Other **API endpoints on the same origin** the SPA already talks to | | Who sends the request | You, directly | The victim's (or your own) browser, with the app's session attached | | Typical fix | Server-side canonicalization + allowlist | Client-side allowlist of route segments before interpolation | | WAF visibility | Payload visible in the path | Payload often hidden in `#hash`, never sent to the server at all | Mechanics that matter: - `new URL('../admin', 'https://app.target.com/api/v1/items/')` resolves in the browser per RFC 3986 — the traversal happens **client-side**, so server logs show a perfectly normal request to `/api/admin`. If your report claims "server traversal", a triager replaying it with curl finds nothing and closes it. Name the layer correctly. - Hash-based routing (`#/page/../../api/...`) never reaches the server in the fragment — the sink is the SPA reading `location.hash`, building a fetch path, and the browser normalizing it. Proof must therefore be a **browser capture**, not a curl transcript. - Encoded traversal (`%2e%2e%2f`) behaves differently per layer: the browser may decode-and-normalize before sending, or pass it through for the server to decode. Test both raw `../` and encoded forms against the same sink and record which one the outgoing request actually carried. ## 8. CHAINS THAT RAISE SEVERITY **CSPT → CSRF (the money chain).** A GET-only sink is usually informational. The report becomes serious when the traversed path lands on a **state-changing endpoint** and the app's fetch wrapper auto-attaches credentials and CSRF headers (`credentials: 'include'`, interceptor-added `X-CSRF-Token`). Then any page that can set the victim's route/hash (a shared link, a stored "view" parameter) makes the victim's browser fire the unintended POST/DELETE. Preconditions to verify before claiming it: (1) the sink accepts attacker-set input in a real victim flow — a link the victim clicks counts; self-only hash editing does not; (2) the target endpoint actually changes state; (3) the token/credentials were attached — show them in the captured request. **CSPT → XSS.** If the traversed endpoint's **response** is rendered into the DOM (`innerHTML`, template interpolation, markdown render), traversing to an endpoint whose response you control (your own profile field, a comment body, an error message echoing input) turns path control into script execution. Also check JSONP-style or `text/html`-negotiated variants of API endpoints — content negotiation on the traversed path is a classic seam. **CSPT → data exposure.** Traversal from a low-privilege route to an admin/reporting endpoint that returns data the UI then displays: the API's own authorization is the only thing that saves it. If the API authorizes by "the UI never links there", that is the finding — demonstrate with your second account (below). ## 9. FRAMEWORK ROUTER SEAMS - **React Router / Vue Router / Angular:** route params (`:id`, `[slug]`) are decoded by the router, then commonly interpolated into data-fetching hooks (`useSWR('/api/items/' + id)`). A param value of `../../users/me` survives routing (it is one segment to the router) and traverses in the fetch. Catch-all routes (`*`, `[...slug]`) are the highest-yield sinks. - **Next.js:** watch `router.query` values flowing into client fetchers, and rewrites/proxies where a client-supplied path segment selects the upstream route. App-router server components blur the layer — re-check §7: if resolution happens server-side it is not CSPT, report it as server traversal/SSRF-class instead. - **Data layers:** React Query / SWR keys built from params, GraphQL clients building REST fallback URLs, and SDK wrappers that join `baseURL + path` with plain string concat (no `URL` normalization discipline) are all fertile. Grep bundles for `baseURL`, `join(`, template-literal fetches, and any custom `apiClient.get(` wrapper — the wrapper is the sink, every call site inherits it. ## 10. DETECTION WORKFLOW (YOUR OWN SESSION ONLY) 1. Instrument first (§3 flagger, or a fetch/XHR hook via DevTools Overrides/Snippets), then drive the app normally with your own test accounts. Every outgoing request whose path contains a segment you typed into a route/query/hash field is a candidate. 2. Fuzz the candidate segment with a traversal ladder: `../`, `../../`, `..%2f`, `%2e%2e/`, `....//` — one step at a time, watching the **resolved** URL in the Network panel, not the string you sent. 3. Map where you land: swap the final segment for known sibling endpoints (profile → settings → admin/export) and note which return 200 with real data vs 403/404. 4. False-positive traps: (a) the router normalizes `../` away before the fetch — the outgoing request never changes: not a sink; (b) traversal resolves but the endpoint enforces authorization and returns 403 for your role — that is the control working, not a bug; claim only what the response proves; (c) you traversed within endpoints your role may legitimately call — no boundary crossed, no report; (d) source-map-only code paths never shipped in the production bundle. ## 11. PROOF DISCIPLINE & REPORTING CHECKLIST - **Canary proof, not other people's data:** create a second test account you own. Plant a unique marker (profile field, object name) in account B. From account A's session, traverse to the endpoint that returns B's canary. Screenshot/record the browser firing the request and the canary in the response. That proves cross-boundary reach with zero third-party data touched. - For CSPT→CSRF: perform the state change **on your own account/object only** (delete your own item, change your own setting) via the victim-flow link, with the auto-attached token visible in the capture. - Report includes: [ ] sink location (bundle file + wrapper/call site) [ ] input source (hash/query/route param) and a real victim delivery path [ ] resolved outgoing request (Copy as fetch) showing traversal + attached credentials/token [ ] canary evidence from your second account [ ] chain claimed (CSRF/XSS/exposure) with each precondition verified, not assumed [ ] layer named correctly (client vs server) [ ] remediation: allowlist segments client-side AND authorize every endpoint server-side — UI reachability is not authorization.