Home/API & HTTP/CORS Header Generator

CORS Header Generator

Generate CORS headers that work the first time — with a simulator that tells you whether a given request preflights, and whether the browser will allow it.

Free Browser-based No signup Copy-ready
Generator Settings
One per line, scheme and host, no trailing slash. Wildcard subdomains are not valid CORS — the server must match and echo the origin.
Methods
Comma-separated. Authorization is never covered by a wildcard — it must always be named.
Headers your JavaScript may read. Without this, only a handful of safe-listed headers are visible to fetch.
Options
Generated Headers ready
Response headers

      
CORS is enforced by the browser, on behalf of the user. It is not server-side access control — curl, a mobile app or any server-side client ignores these headers entirely. Never use CORS as authorisation.

How it works

1

Pick a scenario

Public API, known origins, credentialed, or static assets.

2

Simulate a request

See whether it preflights and exactly why it would be blocked.

3

Ship the config

Nginx, Apache, Express, Vercel or a Cloudflare Worker, preflight included.

The three bugs behind almost every CORS error

CORS failures are famously opaque because the browser reports them from the client side, where the useful detail is deliberately hidden. Nearly all of them come down to three causes.

1. Wildcard plus credentials

Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true cannot coexist. The browser rejects the response outright. The fix is to match the Origin header against an allowlist and echo that single value back — a wildcard is not a shortcut here, it is a different mode.

2. Preflight hitting your auth layer

A browser sends OPTIONS without cookies or an Authorization header. If your authentication middleware sits in front of it and answers 401, every non-simple request fails — and the browser reports it as a CORS error, so you go looking in entirely the wrong place. Answer preflight before authentication.

3. Missing Vary: Origin

If you echo the origin but omit Vary: Origin, any shared cache may store the response for one origin and serve it to another. In front of a CDN this hands your CORS grant to sites you never allowlisted. It also causes intermittent failures that look like a flaky network, because the outcome depends on who warmed the cache.

And one misconception

CORS does not protect your server. The request arrives and executes; the browser merely withholds the response from the calling page. Anything that must be restricted needs real authorisation.

Any POST with Content-Type: application/json is preflighted — JSON is not one of the three simple content types. That single fact explains most "it works in Postman but not in the browser" reports.

Frequently Asked Questions

View all FAQs
How do I fix a CORS error?
Read whether the failure is on the preflight or the actual request. If preflight, your server must answer OPTIONS with a 2xx and the right Access-Control-Allow-* headers before authentication runs. If the actual request, check that the origin is echoed correctly and that a wildcard is not combined with credentials.
Why does my request work in Postman but not the browser?
Because CORS is enforced only by browsers. Postman, curl and server-side clients ignore it completely. A request succeeding there tells you the endpoint works; it says nothing about your CORS headers.
Can I allow multiple origins?
Not in a single header — Access-Control-Allow-Origin takes one value or *. The server must compare the incoming Origin against an allowlist and echo back the matching value, and send Vary: Origin alongside it.
Can I use a wildcard subdomain?
No. https://*.example.com is not valid in this header. Match the pattern server-side and echo the exact origin that was sent.
Why is my POST preflighted?
Almost certainly Content-Type: application/json. Only application/x-www-form-urlencoded, multipart/form-data and text/plain count as simple, so every JSON POST triggers an OPTIONS request first.
Does CORS make my API secure?
No. It restricts what other websites' JavaScript may read in a user's browser. It does not stop anyone calling your API directly. Authentication and authorisation are separate and still required.

CORS headers: preflight, credentials and why the errors are so opaque

This CORS header generator builds the Access-Control-* response set for four common scenarios and includes a simulator that shows whether a given request preflights and whether the browser will allow it. Below: what CORS actually protects, and the three bugs behind most failures.

What CORS is for

Browsers enforce the same-origin policy: script on one origin cannot read responses from another. That is what stops a malicious page reading your webmail in a background request while you are logged in.

CORS is the controlled exception. A server opts in by returning Access-Control-* headers saying which origins may read its responses. The browser enforces the answer.

The consequence people miss: CORS protects the user, not the server. A cross-origin request that fails CORS has usually still arrived at your server and still executed. The browser simply refuses to hand the response back to the calling page. Anything that must not happen requires authorisation, not CORS.

This is why an endpoint "works in Postman but not in the browser". Postman, curl and every server-side client ignore CORS entirely. Success there proves the endpoint works and tells you nothing about your headers.

Simple requests and preflight

Some cross-origin requests go straight out. Others are preceded by an OPTIONS request asking permission first. A request is simple — no preflight — only if all three hold:

  • The method is GET, HEAD or POST.
  • The Content-Type is application/x-www-form-urlencoded, multipart/form-data or text/plain.
  • There are no non-safelisted request headers.
RequestPreflight?Why
GET, no custom headersNoSimple.
POST form-encodedNoSimple content type.
POST JSONYesJSON is not a simple content type.
GET with AuthorizationYesNon-safelisted header.
PUT, PATCH, DELETEYesNot a simple method.

application/json is not on that list. Every JSON POST is therefore preflighted, which is the single most common surprise in the whole topic. Adding an Authorization header also forces a preflight regardless of anything else.

Preflight must not require authentication

This causes more wasted debugging than anything else in CORS.

The browser sends the OPTIONS preflight without cookies and without an Authorization header, by design — it is asking whether it may send the real request, so it does not yet send credentials.

If your authentication middleware runs first and returns 401 for the unauthenticated OPTIONS, the preflight fails. The browser then reports a CORS error, and you spend an afternoon adjusting Access-Control-Allow-Origin when the headers were never the problem.

  1. Handle OPTIONS firstAnswer preflight before any auth middleware in the chain.
  2. Return 204No body needed. Any 2xx works; 204 is conventional.
  3. Echo the CORS headers on itThe preflight response carries the permissions, not the actual response.
  4. Do not require a tokenThere will not be one.
  5. Cache itAccess-Control-Max-Age avoids paying for the round trip on every call.
When debugging, look at the OPTIONS request in the network tab specifically, not the failed GET or POST underneath it. If OPTIONS returned 401, 403, 404 or 500, that is your bug — the headers on the real request are irrelevant until preflight passes.

Credentials change the rules

Sending cookies or an Authorization header cross-origin requires opt-in on both sides: credentials: 'include' in the client, and Access-Control-Allow-Credentials: true on the server. Three restrictions then apply:

  • Access-Control-Allow-Origin cannot be *. It must be a specific echoed origin. The browser rejects the wildcard outright.
  • Access-Control-Allow-Headers: * stops meaning "any header" and is treated as a literal asterisk. List headers explicitly.
  • The same applies to Access-Control-Expose-Headers.
Never allowlist the null origin with credentials enabled. Sandboxed iframes, file:// documents and certain redirects all produce a null origin, so any site can obtain one. It is not a safe identifier.

And a security point: an origin on a credentialed allowlist can act as the logged-in user. Only list origins you control, and treat adding one as a privilege grant rather than a configuration change.

Vary: Origin is not optional

Because Access-Control-Allow-Origin holds one value, supporting multiple origins means reading the request's Origin header and echoing it back. That makes the response depend on a request header — and caches need telling.

Without Vary: Origin, a CDN or reverse proxy may store the response generated for https://app.example.com and serve it, headers included, to a request from anywhere else. The second origin receives an Access-Control-Allow-Origin naming the first, which usually just breaks — but with the right cache ordering it hands a CORS grant to an origin you never allowlisted.

The symptom is intermittency: it works, then it does not, depending on who warmed the cache. That signature almost always means a missing Vary.

Reading response headers

By default, JavaScript can only read six response headers cross-origin: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified and Pragma.

Anything else — a pagination count, a rate-limit header, a Link header, a custom request ID — is invisible unless you name it in Access-Control-Expose-Headers. The header is present on the wire and in the network tab, which makes this confusing: developers can see it in DevTools and cannot read it in code.

If a header is visible in DevTools but undefined in your code, you need Access-Control-Expose-Headers. Nothing is wrong with the request.

Related searches

cors header generatoraccess-control-allow-origincors preflight optionsfix cors errorcors credentials wildcardvary origin headercors multiple originsaccess-control-expose-headerscors nginx configwhy is my post preflightedcors express configaccess-control-max-age