Blog

CORS Is Not About Your Server. That's Why It's Confusing.

September 13, 2026Xerat023 min read
Share
CORS Is Not About Your Server. That's Why It's Confusing.

The single most disorienting thing about a CORS error is that the request the browser blocked would have worked fine — the server processed it, sent back a valid response, and the browser threw it away anyway. curl doesn't hit this. Postman doesn't hit this. A server-to-server call doesn't hit this. That's not because the server behaves differently for those tools; it's because CORS isn't a server-side restriction being applied inconsistently — it's a browser restriction, and only browsers enforce it.

The same-origin policy is the default; CORS is the exception

Browsers block a page's JavaScript from reading a cross-origin response by default — that's the same-origin policy, and it exists to stop a malicious page from silently reading data from, say, your logged-in banking session in another tab. CORS (Cross-Origin Resource Sharing) is the mechanism a server uses to say "actually, it's fine for JavaScript on this other origin to read my responses," via response headers like Access-Control-Allow-Origin. No matching header, no permission granted — and the browser discards the response even though it arrived successfully. This is why curl and Postman never see the problem: they don't enforce same-origin policy at all, because it's a browser-JS protection, not an HTTP-level one.

Why some requests trigger an extra round trip and some don't

A "simple" request (GET/POST/HEAD, with only a small allowlist of headers and content types) goes straight to the server, and the browser just checks the response headers before deciding whether to hand the body to your JavaScript. Anything else — a custom header, a Content-Type: application/json POST in most configurations, a PUT or DELETE — triggers a preflight: the browser sends an OPTIONS request first, asking the server to confirm which origins, methods, and headers it allows, before sending the actual request at all. A server that doesn't respond correctly to that OPTIONS request fails the preflight, and the real request never goes out — a different, more confusing failure than "the response was blocked," because from the outside it looks like the request simply vanished.

The header combination that trips people up specifically

Access-Control-Allow-Origin: * and credentialed requests (cookies, or an Authorization header sent with credentials: 'include') don't mix — a browser will refuse to expose the response to a wildcard-origin request that also carried credentials, no matter what the server sends. This is a deliberate spec restriction, not a bug: an API that both accepts credentials and allows any origin would be exactly the CSRF-adjacent hole the same-origin policy exists to prevent. If credentials are involved, the server has to echo back the specific requesting origin, not a wildcard.

What this means once a mock enters the picture

A mock endpoint is still an HTTP endpoint a browser calls exactly the same way it'd call the real one — the same-origin rules don't relax because the response is fake. If a frontend at localhost:3000 calls a mock served from a different origin, it needs the exact same Access-Control-Allow-Origin handling a real backend would need, and a mocking setup that's silently more permissive in dev than the real API will be in production is a good way to ship a CORS surprise the week you go live. It's worth checking explicitly rather than assuming "it's just a mock" makes the browser's rules not apply — they apply exactly as strictly either way.

X

Xerat02

Building MockBase.