# 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.

Canonical: https://scaplet.com/glossary/cors

Glossary Glossary · Performance

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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fcors%20(%22CORS%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fcors%20(%22CORS%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fcors%20(%22CORS%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fcors%20(%22CORS%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

## 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

_01_At 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

_02_At a glance

## Anatomy of a preflight

Header

### `Origin`

Direction

Browser to server

Meaning

The page's origin

Header

### `Access-Control-Request-Method`

Direction

Browser to server

Meaning

Method the real request will use

Header

### `Access-Control-Request-Headers`

Direction

Browser to server

Meaning

Non-simple headers the real request will send

Header

### `Access-Control-Allow-Origin`

Direction

Server to browser

Meaning

One origin, or `*` for requests without credentials

Header

### `Access-Control-Allow-Methods`

Direction

Server to browser

Meaning

Methods the preflight approves

Header

### `Access-Control-Allow-Headers`

Direction

Server to browser

Meaning

Request headers the preflight approves

Header

### `Access-Control-Max-Age`

Direction

Server to browser

Meaning

Seconds the preflight result may be cached

Preflight request and response, adapted from MDN

```
OPTIONS /doc HTTP/1.1 Host: bar.other Origin: https://foo.example Access-Control-Request-Method: POST Access-Control-Request-Headers: content-type,x-pingother HTTP/1.1 204 No Content Access-Control-Allow-Origin: https://foo.example Access-Control-Allow-Methods: POST, GET, OPTIONS Access-Control-Allow-Headers: X-PINGOTHER, Content-Type Access-Control-Max-Age: 86400 Vary: Accept-Encoding, Origin
```

MDN says the default `Access-Control-Max-Age` is 5 seconds and that browsers cap the value they accept. Without a longer value, browsers repeat the `OPTIONS` call often.

_03_Good 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](/glossary/http-caching).

Wildcard plus cookies fails

By default cross-origin `fetch()` sends no cookies. With `credentials: "include"`, the response must carry `Access-Control-Allow-Credentials: true`, and `Access-Control-Allow-Origin` must name one origin. If it is `*`, the browser blocks the response and reports a CORS error. MDN says the same applies to `*` in the allow-headers, allow-methods and expose-headers lists.

_04_Checklist

## Check it in 2 minutes

1. 01 Is `Access-Control-Allow-Origin` your exact page origin, or `*` when no cookies are involved?
2. 02 Do the allowed methods and headers cover what the real request sends?
3. 03 Does a redirect sit in front of the endpoint? MDN notes that redirects after a preflight fail in some browsers.
4. 04 Does `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)'
```

**The browser console has the real reason**MDN says errors are opaque to JavaScript: your code only learns that the request failed. The console message names the actual cause.

Sources · 1

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- mozilla.org

1. 01 [Cross-Origin Resource Sharing (CORS) (MDN)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) developer.mozilla.org · checked 2026-11-01

Questions

## Asked a lot.

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

_01_ Does 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.

_02_ Does 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.

## Keep learning

[All glossary](/glossary)

[Learn Content Security Policy Performance](/glossary/content-security-policy) [Related HTTP status codes Crawling and indexing](/glossary/http-status-codes) [Read next Security headers Technical SEO](/glossary/security-headers) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in glossary
[Cornerstone content](/glossary/cornerstone-content) [Cost per click (CPC)](/glossary/cost-per-click) [CPM (cost per mille)](/glossary/cpm)

More in Performance
[Viewport meta tag](/glossary/viewport-meta-tag) [WebP](/glossary/webp) [AVIF](/glossary/avif) [bfcache (back/forward cache)](/glossary/bfcache) [Brotli compression](/glossary/brotli-compression) [Cache-Control](/glossary/cache-control) [CDN](/glossary/cdn) [Chrome UX Report (CrUX)](/glossary/chrome-ux-report) [Content Security Policy](/glossary/content-security-policy) [Content-Length (HTTP header)](/glossary/content-length) [Core Web Vitals](/glossary/core-web-vitals) [Core Web Vitals report](/glossary/core-web-vitals-report) [CORS](/glossary/cors) [Critical CSS](/glossary/critical-css) [Critical rendering path](/glossary/critical-rendering-path) [Cumulative Layout Shift (CLS)](/glossary/cumulative-layout-shift) [dns-prefetch](/glossary/dns-prefetch) [Edge caching](/glossary/edge-caching) [fetchpriority](/glossary/fetchpriority) [First Contentful Paint](/glossary/first-contentful-paint) [First Input Delay (FID)](/glossary/first-input-delay) [font-display](/glossary/font-display) [Gzip compression](/glossary/gzip-compression) [HTTP caching](/glossary/http-caching)

Terms on this page
[HTTP caching](/glossary/http-caching)

Free · 2 minutes

## Know the term. _Now check your site._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **+212%** organic clicks in 90 days Ledgerly
