JSON CSRF
A CSRF attack targeting endpoints that accept JSON content-type, often exploiting misconfigured CORS or content-type handling to forge API requests.
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.
Why JSON CSRF is Harder
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.
Vulnerable Configurations
- Server accepts any Content-Type
- Permissive CORS (
Access-Control-Allow-Origin: *with credentials) - CORS whitelist bypass via null origin
- Missing CSRF token validation on API endpoints
Prevention
- Require and validate
Content-Type: application/json - Use CSRF tokens even for API endpoints
- Implement strict CORS policies
- Use SameSite cookies