--- name: hunt-cors description: CORS — origin reflection, null origin, preflight abuse, wildcard detection. Establishes whether credentialed cross-origin reads are actually possible. --- # CORS ASSESSMENT **Core:** the only question that matters is whether a hostile origin can read an authenticated response. A reflected `Origin` without `Access-Control- Allow-Credentials: true` is not exploitable and must not be reported. ## DETECTION ```bash curl -s -I -H "Origin: https://evil.com" "https://target.com/api/userinfo" | grep -i "access-control" # ACAO reflects evil.com AND ACAC: true → credentialed read is possible curl -s -I -H "Origin: null" "https://target.com/api/userinfo" | grep -i "access-control" # Also check the OPTIONS preflight response, which is what the browser enforces curl -s -X OPTIONS -H "Origin: https://evil.com" \ -H "Access-Control-Request-Method: POST" \ -H "Access-Control-Request-Headers: authorization" \ "https://target.com/api/userinfo" -D- -o /dev/null ``` ## WHAT ACTUALLY MATTERS ``` Origin reflected + ACAC: true + sensitive response → exploitable Origin reflected + ACAC absent/false → NOT exploitable ACAO: * (no credentials) → NOT exploitable on authed data Null origin + ACAC: true → exploitable from a sandboxed iframe Trusted subdomain list + wildcard → check which hosts are actually trusted HTTP endpoint missing origin check → may bypass an HTTPS-only policy ``` ## PROOF (minimum sufficient) To confirm the read, show the response body actually crosses origins under `withCredentials` — a PoC page plus the returned payload. **Do not then use the stolen data to act** (no account takeover, no state change). A single demonstrated cross-origin read is the complete finding. ## REPORTING NOTES - Report the credentialed read and the data it exposes. That is the severity. - Where it *could* compound with XSS on a trusted subdomain, note it as a compound-risk line; do not go find the XSS to justify a higher severity. - `Access-Control-Allow-Origin: *` on public, non-credentialed endpoints is correct behavior — reject it (Gate 6). --- ## THE COMPOUND RISK — CORS `*` + UNAUTHENTICATED API `Access-Control-Allow-Origin: *` on its own is *not* a finding when the endpoint serves no credentialed data. But it becomes critical when paired with another weakness, and this pairing is more common than it should be. **The pattern:** ``` API accepts writes without authentication AND returns Access-Control-Allow-Origin: * → any website on the internet can make authenticated admin calls ``` This is not a theoretical chain. On a live target, an unauthenticated `POST /api/admin/products` that returns `ACAO: *` means a malicious website can create, modify, or delete products in every visitor's browser session — with the victim's IP, from the victim's network, with no credential needed. The CORS header turns a server-side auth failure into a client-side exploit that any site can trigger. **Test for it specifically:** ```bash # After finding an unauthenticated write endpoint, check the CORS header curl -s -I -H "Origin: https://attacker.com" \ "https://target.com/api/admin/products" | grep -i "access-control" ``` **If ACAO is `*` (or reflects the origin) on an unauthenticated write endpoint, report it as a compound finding.** The base finding is the missing auth; the compound risk is that the missing auth is reachable from any origin. This is the difference between a Critical that one team fixes and a Critical that gets a security advisory. **Do not build the exploit page.** Report the header combination and the endpoint. The owner can reproduce it in one curl command. --- ## ORIGIN VALIDATION PATTERNS — KNOW WHICH ONE YOU ARE LOOKING AT Not all reflections are the same bug. Classify the server's validation logic before writing the report; the class determines exploitability and the fix. ``` REFLECTION Any Origin value echoed back verbatim + ACAC: true → broken for every endpoint under this middleware. ALLOWLIST Fixed list compared exactly → test list hygiene: dead entries, http:// entries, staging/dev origins still trusted in production. SUBSTRING MATCH Origin accepted if it *contains* a trusted domain → evil-example.com and example.com.evil.com both pass. SUFFIX MATCH Origin accepted if it *ends with* a trusted string → fakeexample.com passes an "example.com" suffix check. REGEX, UNANCHORED Trusted pattern not anchored at both ends → exampleXcom, example.com.attacker.io variants pass. NULL ORIGIN "null" explicitly trusted (sandboxed iframe, redirect, file://, data: URL all send Origin: null) → any site can mint this origin; equivalent to reflection. WILDCARD + CREDS ACAO: * with ACAC: true — browsers refuse this combo, so its presence signals hand-rolled CORS code; test the actual endpoints for reflection behind it. ``` Subdomain trust deserves its own pass: if `*.example.com` is trusted, the finding's real severity is set by the weakest trusted subdomain. Check for dangling DNS / takeover candidates and known XSS-prone legacy hosts on the trusted set, and say which subdomain class you relied on — do not silently assume one is exploitable. ## SIMPLE REQUESTS vs PREFLIGHT — TEST THE PATH THE BROWSER TAKES A `curl -I` HEAD check can lie in both directions. Browsers enforce the preflight result, not the response headers on a request they never send. ``` SIMPLE REQUESTS GET/HEAD/POST with safelisted headers and content types (text/plain, form encodings) skip preflight entirely. → the request fires cross-origin regardless; only the READ is gated by ACAO on the actual response. PREFLIGHTED Custom headers (Authorization, X-*), JSON content type, PUT/DELETE/PATCH → OPTIONS must bless origin, method AND headers, or the browser blocks the real request. MISMATCH TRAP GET reflects origin, OPTIONS does not (or vice versa). → report only what the enforced path permits; a GET-only reflection still leaks every GET-readable resource. HEADER GAP Preflight blesses origin but not your header → try the same read as a simple request: move the token from a custom header into a cookie-authenticated GET. ``` Verify with the real sequence: send the OPTIONS exactly as the browser would (`Origin`, `Access-Control-Request-Method`, `Access-Control-Request- Headers`), then the actual request, and record both responses. ## CACHEABLE CORS RESPONSES If the CORS decision is cached, one origin's blessing can be served to another. Check for `Access-Control-Max-Age` on preflights and shared-cache storage of responses carrying ACAO: ``` - Preflight cached for hours (max-age 86400+) → a policy tightened later keeps being bypassed by browsers holding the old preflight. - Response cached WITHOUT Vary: Origin → the cache stores the copy generated for the reflected attacker origin and serves its ACAO to everyone; conversely a benign cached copy can mask the bug in retests. - Missing Vary: Origin on an origin-dependent response is itself the reportable defect when a shared cache sits in front. ``` Always retest through the cache (repeat the request, watch `Age`/cache status headers) and once with cache-busting parameters before concluding. ## WEBSOCKETS — CORS DOES NOT APPLY The WebSocket handshake is not CORS-checked. Browsers send cookies on the upgrade request and no `Access-Control-*` gate exists; the only defence is the server validating `Origin` itself on the handshake. ``` - Open a socket from a foreign Origin (or with curl, a spoofed Origin header) using your OWN account's session. - Handshake accepted + channel messages readable → cross-site WebSocket hijacking (CSWSH): full duplex, often worse than a CORS read. - Check whether the socket accepts the session via cookie only; token-in- URL or first-message auth changes the analysis — record which. ``` ## PROVING DATA THEFT — THE SELF-HOSTED POC Header screenshots are a lead; the finding is a page on an origin you control reading an authenticated response from an account you own. ``` 1. Host a minimal page on your own origin (localhost is NOT equivalent — use a real distinct origin or a tunnel hostname). 2. Log the TARGET into account A (yours) in the same browser. 3. The page runs fetch(targetEndpoint, {credentials: 'include'}) and displays the returned body on the page itself. 4. Capture: the page source, the browser network log showing Origin + ACAO + ACAC, and the rendered stolen body (account A's own data only). 5. Repeat unauthenticated / with account B logged out as negative control: the read must fail or return only public data. ``` Never point the PoC at another user's session, never exfiltrate the data off the page, and never let the page perform writes. Own accounts, own data, read-only — the same discipline as the proof section above. ## FALSE-POSITIVE TRAPS ``` - Reflection on a LOGIN or PUBLIC endpoint only — no authenticated data is readable; the middleware may still be safe where it matters. Test the authenticated surface before claiming the class. - ACAC: true but auth is a bearer token in a custom header the victim's browser never attaches cross-origin → no credentialed read in practice. - Reflection present only on error pages / 404s with empty bodies. - CDN or WAF reflecting Origin at the edge while the origin server does not — confirm the body is the real API response, not an edge error. - Browser-blocked combos reported from curl alone: if a real browser refuses the read, there is no finding. ``` ## ESCALATION ``` Credentialed read of profile/PII → widen within your own accounts: tokens, API keys, internal IDs in other authenticated GET responses readable the same way. Read exposes CSRF tokens or session-bound data → note the compound line (state change becomes possible); do not perform the state change. Trusted-subdomain reflection → the escalation is the weakest trusted host; name it, don't hunt it. WebSocket handshake without Origin check → separate finding (CSWSH), usually rated above the CORS read. ``` ## REPORTING CHECKLIST ``` [ ] Validation class identified (reflection / allowlist / substring / suffix / regex / null) with the bypassing Origin value shown [ ] Preflight AND actual response captured for the enforced path [ ] ACAC: true and authenticated, sensitive body proven — not inferred [ ] Self-hosted PoC on a real foreign origin, own account, read-only [ ] Negative control (logged out / untrusted origin) recorded [ ] Vary: Origin and preflight max-age noted where a cache is in front [ ] Public/unauthenticated reflections explicitly excluded from scope [ ] Fix stated: exact-match allowlist, never reflect, Vary: Origin ```