Review credentialed browser APIs: CSRF writes and CORS reads
Cookie-backed browser APIs need two checks on the same PR: CSRF controls on mutations and CORS rules on credentialed reads. This case merges those reviews so you do not ship echo-Origin ACAO beside JSON routes that skip CSRF tokens.
Cursor, Claude Code · Coding · 45 min · Deep
Outcome
One PR comment with a mutation table (CSRF control per route) and a credentialed-route table (ACAO rule + allowlist source); Blocks called out before merge.
Steps
- 1
Split the diff into write vs read paths
Mark cookie-auth POST/PUT/PATCH/DELETE first, then ACAO headers on JSON that returns account-specific data. Mixing them in one paragraph hides echo-Origin fixes that skip CSRF.
- 2
Run a two-origin preflight check
From your integration tests, confirm disallowed Origin fails and first-party Origin succeeds on the same credentialed route. Paste test names into the PR comment.
- 3
Link session cookie review when flags move
SameSite changes belong in jwt-session-cookie-security-review-skill-md. Load that case when Set-Cookie edits land with CSRF or CORS tweaks.
Copy prompt
The prompt to paste
Review this PR for credentialed browser security: CSRF on state-changing routes and CORS on routes that return user-specific JSON under cookie auth. Repository facts: [session cookie names and SameSite/Secure/HttpOnly flags in diff] [CSRF middleware or token helper paths] [where Access-Control-Allow-Origin is set — app vs CDN vs edge] [browser mutation routes: forms, server actions, /api JSON with cookies] PR context: [PR link or diff] ## Part 1 — CSRF (writes) Inventory POST/PUT/PATCH/DELETE routes that accept session cookies. For each: - Named control: synchronizer token, double-submit header, Origin allowlist, or documented SameSite-only policy approved for that route. - Block: JSON /api exempt from CSRF while cookies authenticate; tokens only in UI but not on server actions; GET that mutates state. ## Part 2 — CORS (credentialed reads) Inventory routes with Access-Control-Allow-Credentials and cookie auth. For each: - Quote ACAO rule: static allowlist vs reflected Origin. - Block: echo req.headers.origin without membership test; ACAO * with credentials; null origin on session JSON routes without audited embed exception. - OPTIONS preflight must not allow broader methods/headers than real responses. ## Cross-check If this PR relaxes CORS on a cookie-auth API, confirm CSRF still holds for mutations from the browser. Findings table + merge recommendation. Rules: - No exploit HTML or step-by-step attack pages. - No live cookies or JWTs in the comment. - Pair with jwt-session-cookie-security-review-skill-md when Set-Cookie flags change in the same PR.
CORS limits cross-origin reads; it does not stop credentialed POSTs from evil sites. Blocking CSRF while echoing Origin still exposes private JSON to malicious pages — both tables must be clean before merge.
Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code.
More in Coding
Get new cases in your inbox
Weekly notes on new use cases and agent workflows. No product pitches.