Free auditStart free
GlossaryGlossary · Performance

CORS

CORS is the header mechanism that lets a server allow cross-origin reads from browser scripts. Preflights, credentials rules, the wildcard trap, and a curl check.

2 min
read
1
sources
Oct 31, 2026
updated
Scaplet Editorial Team
author
In one line

CORS (cross-origin resource sharing) is an HTTP-header mechanism that lets a server tell browsers which other origins may read its responses from JavaScript. Browsers block cross-origin reads by default under the same-origin policy. The server opts in with headers such as Access-Control-Allow-Origin.

30-second check

Is this costing your site traffic?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode

At a glance

4 facts from the sources below
The browser, not the server
Enforced by
`Access-Control-Allow-Origin`
Core response header
`OPTIONS`
Preflight method
Not allowed
Wildcard with credentials
01At a glance

Simple requests and preflights

Some cross-origin requests go straight through. Others make the browser ask permission first with an OPTIONS request, called a preflight. MDN lists what keeps a request simple: the method is GET, HEAD or POST, only CORS-safelisted headers are set by hand, and Content-Type is application/x-www-form-urlencoded, multipart/form-data or text/plain.
Request

GET with no custom headers

Preflight?
No
Example
fetch("https://bar.other")
Request

POST with Content-Type: text/plain

Preflight?
No
Example
A form-style post
Request

POST with Content-Type: application/json

Preflight?
Yes, JSON is not a simple type
Example
Most API calls
Request

Any request with a custom header

Preflight?
Yes
Example
X-PINGOTHER: pingpong
Request

PUT or DELETE

Preflight?
Yes
Example
REST updates
03Good to know

Credentials and the wildcard trap

Preflight requests never include credentials, yet the preflight response must still allow them. When you pick the allowed origin dynamically from a list, send Vary: Origin too, so shared caches keep one response per requesting origin. See HTTP caching.

04Checklist

Check it in 2 minutes

  1. 01Is Access-Control-Allow-Origin your exact page origin, or * when no cookies are involved?
  2. 02Do the allowed methods and headers cover what the real request sends?
  3. 03Does a redirect sit in front of the endpoint? MDN notes that redirects after a preflight fail in some browsers.
  4. 04Does Vary: Origin appear when you echo the origin?
Simulate the browser's preflight
curl -si -X OPTIONS https://api.example.com/items \
  -H 'Origin: https://app.example.com' \
  -H 'Access-Control-Request-Method: POST' \
  -H 'Access-Control-Request-Headers: content-type' \
  | grep -i -E '^(HTTP|access-control|vary)'
Sources · 1

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • mozilla.org
  1. 01Cross-Origin Resource Sharing (CORS) (MDN)developer.mozilla.org · checked 2026-11-01
Questions

Asked a lot.

2 questions people ask next, answered from the sources on this page.

01Does CORS protect my API from other callers?

No. CORS only controls whether scripts in a browser can read a response. MDN says servers still need their own defenses, such as CSRF protection, because simple requests can be sent cross-site like form submissions.

02Does CORS apply to images and fonts?

Yes in some cases. MDN lists images with the crossorigin attribute, module scripts, web fonts, WebGL textures and canvas reads as places CORS applies beyond fetch and XMLHttpRequest.

Free · 2 minutes

Know the term. Now check your site.

The free audit reads robots.txt, sitemaps, status codes, canonicals, redirects and structured data.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • +212% organic clicks in 90 days Ledgerly