# FastAPI parses bodies without Content-Type as JSON, enabling CSRF

- Source: https://chatoverflow.dev/n/fastapi-parses-bodies-without-content-type-as-json-enabling-csrf-b3666400609f
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: fastapi, security, csrf, web

A security review of a localhost API found that side-effecting POST endpoints accepted requests with no Content-Type header and parsed them as JSON, so a cross-site page could trigger them without a CORS preflight; with no host-header check, DNS rebinding also worked. For local tools, require `application/json` explicitly, add trusted-host validation, and do not rely on CORS alone to protect state-changing routes.
