JSON CSRF

CSRF against endpoints that expect a JSON body, exploiting the gap between “requires application/json” (which would force a CORS preflight) and what the server actually parses: CORS-safelisted content types, lenient body parsers, permissive credentialed CORS, or alternative body channels.

How it works

A cross-site request avoids preflight only if it is “simple”: method GET/HEAD/POST, no custom headers, and Content-Type in application/x-www-form-urlencoded, multipart/form-data, text/plain. fetch with Content-Type: application/json or any custom header is preflighted, so a correctly strict JSON API is not reachable cross-site. The bug is the server not being strict:

  • it ignores Content-Type and JSON-parses whatever arrives;
  • it accepts form encodings on the same route (framework converts to the same model);
  • its CORS policy reflects Origin with Access-Control-Allow-Credentials: true, so the preflight succeeds;
  • it accepts the body via another channel (query parameter), or a browser feature sends a non-form content type without preflight.

Cookie delivery still has to work: cross-site POST needs SameSite=None (or a same-site origin, or the Lax+POST window) — see SameSite Cookies.

Techniques / payloads

1. text/plain form producing a JSON-shaped body. enctype="text/plain" serializes name=value; split the JSON so the = lands inside a throwaway key:

<form action="https://target/api/profile" method="POST" enctype="text/plain">
  <input type="hidden" name='{"email":"a@evil.tld","x":"' value='"}'>
</form><script>history.pushState('','','/');document.forms[0].submit()</script>

Body: {"email":"a@evil.tld","x":"="}. Works when the parser ignores the declared type or tolerates the extra key.

2. Same route, other encodings. Re-send as urlencoded / multipart; also try text/plain; application/json — some servers match on the trailing token.

3. Credentialed CORS misconfiguration. Dynamic ACAO reflection + ACAC: true lets attacker JS send real application/json (and PUT/PATCH) with cookies. Wildcard * with credentials is rejected by browsers, so reflection is the bug.

4. Body via query parameter. Apache Juneau’s REST server replaced the request body with a content query parameter on every method including GET (CVE-2026-73099) — a top-level link delivers an arbitrary body without preflight, defeating method/content-type-based protections.

5. Hyperlink auditing (<a ping>). Chromium sends a credentialed cross-origin POST with Content-Type: text/ping and no preflight. Middleware that only inspects form content types skips Origin/Sec-Fetch-Site checks (Hono csrf()). Body is fixed, so only path/query-driven actions are reachable.

6. Method downgrade. PUT/PATCH/DELETE are preflighted; try POST with _method or override headers (Method Override CSRF).

7. Same-origin JS primitives. With XSS on the target or a same-site sibling, fetch with JSON and the app’s own CSRF header is trivially same-origin/same-site — this is how stored XSS turned a keyed JSON API into ATO in one Bugcrowd report. Legacy .swf-based delivery is historical.

GraphQL. Mutations accepted over GET (?query=mutation…) or as application/x-www-form-urlencoded POST are plain CSRF; the GraphQL-over-HTTP draft says GET MUST NOT execute mutations. Verify DAST “CSRF over GET” findings by checking whether a mutation actually executes.

Notable cases

Defenses

  • Reject any Content-Type other than application/json on JSON routes; disable simple content types where not needed (OWASP “disallowing simple requests”).
  • Require a custom header (X-CSRF-Token, X-Requested-With) — forces preflight — and actually enforce it on all encodings.
  • Never reflect arbitrary Origin with credentials; exact allow-list, no regex over subdomains.
  • Treat non-form content types (text/ping, unknown) as untrusted in CSRF middleware; check Origin/Sec-Fetch-Site regardless of content type.
  • GraphQL: no mutations over GET; require JSON POST.

See also: CORS Misconfiguration

Sources