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.
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 POSTThe only methods that can skip a preflight
Accept, Accept-Language, Content-Language, Content-Type, RangeHeaders you may set by hand and still count as simple; Range only with a single range
Content-Type: application/jsonNot a safelisted type, so a JSON POST always triggers a preflight
application/x-www-form-urlencoded, multipart/form-data, text/plainThe three Content-Type values that keep a request simple
Safelisted value over 128 bytes, or over 1024 in totalTurns a safelisted header unsafe and forces a preflight
Authorization: Bearer ...Any non-safelisted header such as Authorization or X-Requested-With triggers a preflight
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/anythingFake a browser preflight; httpbin answered 200 with the origin echoed and both headers allowed
Access-Control-Request-Method: PUTSent by the browser in the preflight: the method the real request will use
Access-Control-Request-Headers: content-type, authorizationSent by the browser: the non-safelisted headers the real request will carry
Access-Control-Allow-Methods: GET, POST, PUT, DELETEServer's answer listing methods it accepts cross-origin
Access-Control-Allow-Headers: content-type, authorizationServer's answer listing request headers it accepts; Authorization is never covered by *
Access-Control-Max-Age: 3600Let 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
Access-Control-Allow-Origin: https://app.example.comAllow exactly one origin; scheme and host must match and there is no trailing slash
Vary: OriginRequired when the allowed origin changes per request, so caches key on Origin
Access-Control-Expose-Headers: X-Request-Id, RateLimitLet JavaScript read these headers; by default only seven safelisted response headers are visible
Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified, PragmaThe CORS-safelisted response headers that scripts can always read
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
xhr.withCredentials = trueThe XMLHttpRequest equivalent of credentials: "include"
Access-Control-Allow-Credentials: trueServer opt-in for credentialed reads; the value is case-sensitive, True fails
No `*` in Allow-Origin, Allow-Headers, Allow-Methods or Expose-HeadersWith credentials, * is either rejected (origin) or read as a literal header name
fetch(url, { mode: "no-cors" })Returns an opaque response with status 0 that your code cannot read; it does not fix CORS
Reason names are Firefox's; Chrome words them differently but the causes match. JavaScript only sees a generic network error, so read the console.
CORSMissingAllowOriginResponse had no Access-Control-Allow-Origin; often an error page from a proxy or a crashed handler
CORSAllowOriginNotMatchingOriginThe header names a different origin, often missing the scheme or with a trailing slash
CORSMultipleAllowOriginNotAllowedTwo Allow-Origin headers, typically app code and nginx both adding one
CORSNotSupportingCredentialsRequest used credentials but the server sent *; echo the origin or drop credentials
CORSPreflightDidNotSucceedThe OPTIONS request failed at the network level, for example blocked or not routed
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 errorIt gives an opaque response you can't read; fix the server headers or proxy the call through your own origin.
Forgetting
Vary: Originbehind a CDNAdd 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.
Related cheat sheets
Sources
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS
- https://fetch.spec.whatwg.org/
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS/Errors
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Max-Age
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Headers
- https://developer.mozilla.org/en-US/docs/Web/API/RequestInit
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.