Skip to content

Menu

CORS Cheat Sheet: Preflight, Credentials and Common Errors

Checked against CORS Fetch Living Standard (last updated 20 Nov 2026) and the MDN CORS guide on 28 November 2026. Each section links to the official docs it was checked against.

This sheet is for back-end and front-end developers staring at a CORS error in the console and asking which side to fix. It follows the Fetch Living Standard as last updated on 20 November 2026 and MDN's CORS guide and error pages. The preflight and origin-echo rows were run with curl against httpbin.org; browser-only behaviour is marked untested.

A preflighted CORS requestA JSON POST or an Authorization header makes the browser send an OPTIONS preflight first; the real request goes out only if the server's answer allows it.BrowserServerNot simple: e.g. Content-Type: application/json orAuthorizationOPTIONS (preflight)Access-Control-Request-Method /-HeadersAllow-Methods, Allow-HeadersMax-Age: 3600 lets the browserreuse itActual requeste.g. PUT with content-type,authorizationAccess-Control-Allow-Originexact origin + Vary: OriginWith credentials: no *, and Allow-Credentials:true
A JSON POST or an Authorization header makes the browser send an OPTIONS preflight first; the real request goes out only if the server's answer allows it.

When to use what

First ask if you need CORS at all. If the browser page and the API can sit behind the same origin, for example via a reverse proxy path like /api, there is nothing to configure and no preflight latency. CORS is for when they genuinely live on different origins.

For a public, read-only API with no cookies, Access-Control-Allow-Origin: * is fine and is the simplest correct answer. The moment a request carries cookies or HTTP auth, the wildcard stops working: you must echo one specific allowed origin, send Access-Control-Allow-Credentials: true, and add Vary: Origin so caches don't serve one origin's answer to another. Keep the allowlist in code and compare exact strings; never reflect whatever Origin arrives.

Preflights cost a round trip. You avoid them by keeping requests simple (GET, HEAD or POST with only safelisted headers and a form or text content type), which rarely suits a JSON API. The practical fix is Access-Control-Max-Age, remembering each browser caps it. The CORS header builder produces a matching header set, the CORS tester shows how a server answers, and CORS explained covers the background.

The safelist rules are defined in the Fetch Standard (https://fetch.spec.whatwg.org/). Safari adds extra limits on Accept, Accept-Language and Content-Language values.

GET, HEAD or POST

The only methods that can skip a preflight

From the docs, not run by us
Accept, Accept-Language, Content-Language, Content-Type, Range

Headers you may set by hand and still count as simple; Range only with a single range

From the docs, not run by us
Content-Type: application/json

Not a safelisted type, so a JSON POST always triggers a preflight

From the docs, not run by us
application/x-www-form-urlencoded, multipart/form-data, text/plain

The three Content-Type values that keep a request simple

From the docs, not run by us
Safelisted value over 128 bytes, or over 1024 in total

Turns a safelisted header unsafe and forces a preflight

From the docs, not run by us
Authorization: Bearer ...

Any non-safelisted header such as Authorization or X-Requested-With triggers a preflight

From the docs, not run by us

Max-Age caps per MDN: Firefox 86400 seconds, Chromium 7200 seconds (since v76). The default is 5 seconds.

curl -si -X OPTIONS -H 'Origin: https://example.com' -H 'Access-Control-Request-Method: PUT' -H 'Access-Control-Request-Headers: content-type, authorization' https://httpbin.org/anything

Fake a browser preflight; httpbin answered 200 with the origin echoed and both headers allowed

Access-Control-Request-Method: PUT

Sent by the browser in the preflight: the method the real request will use

Access-Control-Request-Headers: content-type, authorization

Sent by the browser: the non-safelisted headers the real request will carry

Access-Control-Allow-Methods: GET, POST, PUT, DELETE

Server's answer listing methods it accepts cross-origin

Access-Control-Allow-Headers: content-type, authorization

Server's answer listing request headers it accepts; Authorization is never covered by *

Access-Control-Max-Age: 3600

Let the browser reuse this preflight for an hour (httpbin sends 3600)

Access-Control-Allow-Origin: *

Let any origin read the response, but only for requests without credentials

Try it: CORS Header BuilderFrom the docs, not run by us
Access-Control-Allow-Origin: https://app.example.com

Allow exactly one origin; scheme and host must match and there is no trailing slash

Vary: Origin

Required when the allowed origin changes per request, so caches key on Origin

From the docs, not run by us
Access-Control-Expose-Headers: X-Request-Id, RateLimit

Let JavaScript read these headers; by default only seven safelisted response headers are visible

From the docs, not run by us
Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified, Pragma

The CORS-safelisted response headers that scripts can always read

From the docs, not run by us

fetch() defaults to credentials: "same-origin", so cross-origin cookies are not sent unless you ask (https://developer.mozilla.org/en-US/docs/Web/API/RequestInit). Third-party cookie blocking can still drop them.

fetch(url, { credentials: "include" })

Send cookies and HTTP auth on a cross-origin request

From the docs, not run by us
xhr.withCredentials = true

The XMLHttpRequest equivalent of credentials: "include"

From the docs, not run by us
Access-Control-Allow-Credentials: true

Server opt-in for credentialed reads; the value is case-sensitive, True fails

From the docs, not run by us
No `*` in Allow-Origin, Allow-Headers, Allow-Methods or Expose-Headers

With credentials, * is either rejected (origin) or read as a literal header name

From the docs, not run by us
fetch(url, { mode: "no-cors" })

Returns an opaque response with status 0 that your code cannot read; it does not fix CORS

From the docs, not run by us

Reason names are Firefox's; Chrome words them differently but the causes match. JavaScript only sees a generic network error, so read the console.

CORSMissingAllowOrigin

Response had no Access-Control-Allow-Origin; often an error page from a proxy or a crashed handler

From the docs, not run by us
CORSAllowOriginNotMatchingOrigin

The header names a different origin, often missing the scheme or with a trailing slash

From the docs, not run by us
CORSMultipleAllowOriginNotAllowed

Two Allow-Origin headers, typically app code and nginx both adding one

From the docs, not run by us
CORSNotSupportingCredentials

Request used credentials but the server sent *; echo the origin or drop credentials

From the docs, not run by us
CORSPreflightDidNotSucceed

The OPTIONS request failed at the network level, for example blocked or not routed

From the docs, not run by us

Worked example: Debug a credentialed API call that fails in the browser

A front end on https://example.com calls an API with cookies and an Authorization header. Reproduce the browser's preflight with curl:

curl -si -X OPTIONS https://httpbin.org/anything \
  -H 'Origin: https://example.com' \
  -H 'Access-Control-Request-Method: PUT' \
  -H 'Access-Control-Request-Headers: content-type, authorization'

httpbin.org answered on 28 Nov 2026 with:

HTTP/2 200
access-control-allow-credentials: true
access-control-allow-headers: content-type, authorization
access-control-allow-methods: GET, POST, HEAD, PUT, DELETE, PATCH, QUERY, OPTIONS
access-control-allow-origin: https://example.com
access-control-max-age: 3600

Read it line by line. The status is 2xx, which a preflight needs. The origin is echoed exactly rather than *, which is what credentials require, and Allow-Credentials is the lowercase literal true. Both requested headers are listed by name, so Authorization passes. If your own server returned * here, or 401 because auth middleware ran before the CORS handler on the OPTIONS request, the browser would block the real call. Repeat the curl without OPTIONS to confirm the actual response carries the same origin header; httpbin echoed it there too. One thing httpbin did not send is Vary: Origin, which your server should add.

Common mistakes

  • Reflecting any incoming Origin with credentials allowed

    Check the origin against an exact allowlist; reflecting everything lets any site read your users' data.

  • Running authentication before the CORS handler

    Let OPTIONS preflights through unauthenticated, since browsers never send credentials on a preflight.

  • Using mode: "no-cors" to silence the error

    It gives an opaque response you can't read; fix the server headers or proxy the call through your own origin.

  • Forgetting Vary: Origin behind a CDN

    Add it whenever Allow-Origin varies, or the CDN will hand one origin's header to everyone.

  • Writing the allowed origin with a trailing slash or no scheme

    Use the serialized origin form, such as https://app.example.com, with no path and no slash.