Catalog My learning Blog
Browser Security Headers: CORS, CSP and Cookies Explained · Phase 2 · Lesson 7 · 7 min read

CORS Simple Requests vs Preflighted Requests

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: Smuggling JSON Past the Preflight with text/plain
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

State exactly which method, header, and Content-Type combinations qualify a cross-origin request as "simple" under the Fetch Standard, explain why that specific set was chosen, and recognize how the text/plain loophole lets an attacker send JSON-shaped bodies without triggering a preflight.

Concept Explanation

The Fetch Standard divides cross-origin requests into two classes. A simple request, more precisely a request that does not require a CORS preflight, is dispatched immediately, and the CORS decision is applied only to the response. Any request that falls outside the simple criteria is preflighted: the browser first sends a separate OPTIONS request asking permission, and only issues the real request if the server approves. Knowing which class a given request falls into explains most surprising CORS behavior.

A request avoids the preflight only if all of the following hold. The method is GET, HEAD, or POST. Every author-set header is on the CORS-safelisted request header list: Accept, Accept-Language, Content-Language, Content-Type subject to the restriction below, plus Range with limits and a small number of client hints. If Content-Type is set, its value must be one of exactly three: application/x-www-form-urlencoded, multipart/form-data, or text/plain. No ReadableStream body is used, and no event listener is registered on the upload object of an XMLHttpRequest.

The reason this exact set exists is backward compatibility, and understanding that reframes the whole design. A plain HTML form could already, before CORS existed and without any JavaScript, issue a cross-origin GET or POST with a body encoded as form-urlencoded, multipart, or text/plain. Those capabilities are historically available to every page on the web with no opt-in whatsoever. The safelist is therefore not a judgment that these requests are safe; it is an acknowledgment that they were always possible, so requiring a preflight for them would break the web without preventing anything an attacker could not already do with a form. Everything outside that set is a capability CORS introduced, and CORS gates it.

That framing immediately exposes a practical trap. An attacker who wants to send a JSON body to an API cross-origin cannot set Content-Type: application/json, because that would trigger a preflight the target server will not approve. But they can set Content-Type: text/plain and put a JSON string in the body. The request is simple, so it is sent directly with cookies attached, and many server frameworks configured leniently, or explicitly set up to parse any body as JSON, will happily parse it. The endpoint is then CSRF-able despite the developer's belief that "it only accepts JSON, so it is preflight-protected." The defense is to require the correct Content-Type strictly on the server and to reject requests that do not carry it, which restores the preflight requirement as a real barrier.

The mirror image of this rule is also useful: adding a single custom header, for example X-Requested-With or an API version header, to every request from your own front end forces a preflight on every cross-origin call to your API. That is a deliberate technique, since it means no third-party page can reach the endpoint at all without first obtaining an approving preflight response, which a properly configured server will never give it. The cost is one extra round trip per unique preflight, which Access-Control-Max-Age can amortize, as the next lesson covers.

RequestPreflighted?Reason
GET with no custom headersNoMethod is safelisted and no non-safelisted header is present
POST with Content-Type: application/x-www-form-urlencodedNoA plain HTML form could always send this
POST with Content-Type: text/plain carrying a JSON stringNotext/plain is safelisted, which is the loophole to defend against
POST with Content-Type: application/jsonYesapplication/json is not one of the three safelisted values
GET with an Authorization or X-Api-Key headerYesAny non-safelisted author-set header forces a preflight
PUT, PATCH, or DELETE with any headersYesThe method itself is not safelisted

Worked Example: Smuggling JSON Past the Preflight with text/plain

The request below is what a malicious page sends when an API accepts JSON but does not enforce the Content-Type. It is a simple request, so no preflight occurs and the browser does not ask the server for permission before sending it.

TypeScript
// On https://evil.example - no preflight is triggered by any of this
fetch('https://api.example.com/v1/account/email', {
  method: 'POST',
  credentials: 'include',
  headers: { 'Content-Type': 'text/plain' },   // safelisted value
  body: JSON.stringify({ email: 'attacker@evil.example' }),
});

// On the wire:
POST /v1/account/email HTTP/1.1
Host: api.example.com
Origin: https://evil.example
Content-Type: text/plain;charset=UTF-8
Cookie: session=...

{"email":"attacker@evil.example"}

// The response is unreadable by evil.example, but the email was changed.

// SERVER-SIDE FIX: reject anything that is not real JSON, which restores
// the preflight as an actual barrier for cross-origin callers.
app.use((req, res, next) => {
  if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
    const ct = (req.headers['content-type'] || '').split(';')[0].trim();
    if (ct !== 'application/json') return res.status(415).end();
  }
  next();
});
A decision tree evaluating a cross-origin request against the simple-request criteria, method, author-set headers, and the three allowed Content-Type values, branching into direct dispatch or a preflight.
A decision tree evaluating a cross-origin request against the simple-request criteria, method, author-set headers, and the three allowed Content-Type values, branching into direct dispatch or a preflight.

Real-World Examples

  • The safelisted Content-Type values exist because an HTML form has always been able to produce them: the 2008 paper "Robust Defenses for Cross-Site Request Forgery" by Barth, Jackson, and Mitchell analyzed exactly this capability when documenting live CSRF flaws at ING Direct and the New York Times, and the Fetch Standard's safelist is the direct codification of "do not preflight what a form could already do."
  • The text/plain content-type bypass is a recurring finding in public bug bounty reports against JSON APIs built on frameworks whose body parsers are configured to accept any content type; Express applications that call express.json() with a permissive type option, and Spring endpoints without a strict consumes constraint, have both been documented as CSRF-able for exactly this reason despite developers assuming the JSON content type made them preflight-protected.
Common PitfallDo not rely on "it only accepts JSON" as a CSRF defense. An attacker can send a JSON body under Content-Type: text/plain without any preflight, and lenient body parsers will accept it. Enforce the exact Content-Type on the server and return 415 for anything else, so the preflight requirement becomes a barrier an attacker genuinely cannot get past.

Review Questions & Answers

Those three are the encodings an ordinary HTML form has always been able to produce cross-origin, with no JavaScript and no opt-in, since long before CORS existed. Preflighting them would break enormous amounts of existing web content while preventing nothing, because an attacker could fall back to a form. application/json was never producible by a form, so it is a capability that CORS introduced, and CORS therefore gates it behind a preflight.

The attacker sets Content-Type to text/plain, which is safelisted, and puts a JSON string in the body. The request qualifies as simple, is dispatched directly with the victim's cookies, and any server whose body parser is not strict about content type will parse it as JSON and act on it. The server stops it by requiring the exact application/json content type and rejecting anything else with 415, which forces a genuine cross-origin caller into a preflight that the server will not approve.

A non-safelisted author-set header forces the browser to preflight the request. A malicious page cannot skip the preflight, and the server will not return an Access-Control-Allow-Headers value approving that header for an untrusted origin, so the real request is never dispatched. The defense works because the preflight decision is made by the browser before any side effect can occur, unlike the response-side CORS check which happens after the damage is done.

It implies the endpoint is directly reachable by any page on the internet with the user's cookies attached, with no browser-side gate at all, since even an image tag can trigger it. CORS will withhold the response, but the state change already happened. State-changing operations must never be exposed on GET, both because GET is defined as safe and idempotent and because it is the request type with the least browser-enforced protection available.