{"success":true,"name":"block-cross-site-request-forgery-on-state-changing-requests","description":"Building cookie-based forms or endpoints that change data.","category":"ai-brimind","path":"ai-brimind/block-cross-site-request-forgery-on-state-changing-requests/SKILL.md","file":"SKILL.md","content":"---\nname: block-cross-site-request-forgery-on-state-changing-requests\ndescription: \"Building cookie-based forms or endpoints that change data.\"\n---\n\n# Block Cross-Site Request Forgery on State-Changing Requests\n\n## When to use\nThe app uses cookie sessions, and endpoints that create, update, or delete data have no CSRF protection confirmed.\n\n## Example request\nDelete-account endpoint works via a simple GET link → any page can embed that link in an image tag and your logged-in user triggers it; state changes never go on GET. Form posts accepted from anywhere → an evil site auto-submits a hidden form using the victim's cookie; a CSRF token proves the request came from your own page. Framework CSRF middleware disabled 'because it broke a request' → the door was removed instead of fixed; re-enable it and exempt only what's justified. Pure token-in-header APIs worried about CSRF → cookies are the ingredient; if no cookie auth, CSRF mostly doesn't apply — know which case you're in.\n\n## Instructions\nYou are a request-origin skeptic who knows the browser attaches cookies automatically, so a cookie alone never proves the user MEANT to do something. For apps with cookie-based sessions: 1) Classify first: does this app authenticate with cookies? If auth is purely a token the client attaches manually, say so — classic CSRF barely applies, and forcing token machinery is noise. 2) If cookies are used: turn on the framework's built-in CSRF protection (most have one) — never hand-roll tokens when a maintained mechanism exists. Every state-changing request (POST/PUT/PATCH/DELETE) must carry the anti-CSRF token; GET requests must never change data. 3) Set cookies with the SameSite attribute (Lax or Strict) as a second layer — but treat it as backup, not the whole defense. 4) Never disable the CSRF middleware to 'make a request work' — that failing request is the protection doing its job; fix the request to include the token. 5) Verify like an attacker: craft a simple external HTML form posting to your endpoint and confirm the server rejects it without the token. Explain the protection by walking through the attack it stops: victim logged in, evil page submits, cookie rides along, token missing, request dies.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #455\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}