CORS Misconfiguration Explained
Last updated:
CORS — Cross-Origin Resource Sharing — is the browser's rule for when one website may read another site's responses: by default it may not, unless the server opts in with an Access-Control-Allow-Origin header. That one header, plus a credentials flag and a preflight handshake, decides whether any website on the internet can read your API as your users. This guide explains the same-origin policy in one sentence, when the browser sends a preflight, how credentials mode works, the three classic misconfigurations and the null origin trap — then shows you how to measure your own server with the CORS Misconfiguration Checker.
The same-origin policy, in one sentence
A page may only read responses from its own origin — same scheme, same host, same port — unless the server of the other origin explicitly opts in. That is the whole same-origin policy: it does not stop a page from sending a request (a form post, an image load, a fetch with no-cors mode all go out), it stops the page from reading the response. The distinction matters because the attack CORS guards against is not a request reaching your server — your server receives cross-origin requests all day — it is a malicious page reading the response that comes back, with the victim's cookies attached.
CORS is the opt-in mechanism the Fetch standard defines for that read. The server opts in by sending Access-Control-Allow-Origin (ACAO) on its response: `*` for every origin, one specific origin for that site, or nothing at all — in which case the browser blocks the read and the page sees a network error, even though the server answered 200. The browser enforces the policy; the server merely declares it. That is why CORS is not access control for your API: curl, a script, or another server ignores it entirely and reads whatever you return. CORS protects the browser's user from a malicious page — it never protects your server from a direct caller.
Simple requests and preflighted requests
Not every cross-origin request gets the same treatment. A simple request — a GET, HEAD or POST with only safelisted headers and a simple content type — goes out immediately, and the browser checks the ACAO on the response afterwards. Everything else is preflighted: before sending the real request, the browser sends an OPTIONS request asking which methods and headers the server allows for this origin, with Access-Control-Request-Method and Access-Control-Request-Headers naming what the real request wants to do. Only if the preflight answers with a matching Access-Control-Allow-Methods list does the real request go out.
The preflight exists because simple requests were already possible before CORS — a form could always POST cross-origin — while the newer capabilities (PUT, DELETE, custom headers, JSON bodies) needed a gate that old servers could answer without changing. Three properties of the preflight matter for operators: browsers do not follow redirects for it, so a preflight that 301s fails the whole request; it is cached for Access-Control-Max-Age seconds, so a bad answer lingers; and its answer is per-origin, so a server that varies its ACAO by Origin must also send Vary: Origin or a shared cache will serve one site's answer to another. The CORS Misconfiguration Checker sends a real preflight — OPTIONS with Access-Control-Request-Method: GET and Access-Control-Request-Headers: authorization, content-type — and reports exactly what comes back.
Credentials mode: both sides must opt in
Cookies and Authorization headers are only exposed to a cross-origin read when both sides opt in. The page must ask for credentials — fetch with credentials: 'include', or an XMLHttpRequest with withCredentials — and the server must answer Access-Control-Allow-Credentials: true together with a specific origin. Either side alone is not enough: a page that asks for credentials against a server that does not allow them gets a blocked read, and a server that allows credentials to a page that did not ask gets a response without them. The two switches exist so that neither side can unilaterally turn a cross-origin read into an authenticated one.
The wildcard breaks this handshake by design. Browsers refuse to honour Access-Control-Allow-Origin: * together with Access-Control-Allow-Credentials: true — the combination is simply not a valid way to say 'everyone, authenticated'. A server that sends both has either opened a public API to credentialed reads by accident, or its author believed a combination that never worked. Either way the config is broken, and the fix is the same in both cases: replace `*` with an explicit allowlist origin and add Vary: Origin, or drop credentials if the API is meant to be public. Note also that the credentials flag is about the browser exposing the response to the page — the server still receives the cookies on the request either way, which is why CORS never stops a cross-site request forgery; that is what SameSite cookies and CSRF tokens are for.
The three classic misconfigurations
First, the reflected origin with credentials: the server echoes the request's Origin header straight back as the ACAO, with Access-Control-Allow-Credentials: true. Any website can then read the API's responses with the victim's cookies — the attacker lures the victim to their page, the page fetches your API, and the victim's browser hands the response over. It is usually written as a convenience ('allow any origin during development') that ships to production, and it is the most dangerous of the three because it is fully exploitable with no victim interaction beyond visiting a page. The fix is a static allowlist: check the incoming Origin against a fixed list and only then send it back — never echo it blindly.
Second, the wildcard with credentials, covered above: `*` plus ACAC true, broken either way. Third, the missing Vary: Origin: the server varies its ACAO by the request's Origin — the correct behaviour for an allowlist — but does not send Vary: Origin, so a shared cache can store the response sent to one site and serve it, ACAO and all, to another origin. The poisoning needs a cache in the path, which CDNs and corporate proxies provide by default, and the fix is one header. A fourth trap deserves its own mention: the `null` origin. ACAO: null matches sandboxed iframes and data: URLs — contexts with no real origin at all — and some frameworks used to emit it as a catch-all for 'no origin'. Never allow `null`: it bypasses origin checks for exactly the contexts that have no origin to check.
How to read the checker's verdicts — and what to fix first
The checker classifies the ACAO it received for a foreign Origin — https://evil.example.com, an origin no allowlist should contain — into six classes: wildcard, reflected, allowlisted (a specific origin that is not the tested one), null, absent, or unparseable. Reflected plus credentials is the critical error; wildcard plus credentials and `null` are errors too; a reflected origin without credentials is a warning (fine for a public API, a leak for anything user-specific); `*` without credentials and an allowlisted origin are infos; no ACAO at all is an info — cross-origin reads are blocked, which is safe, just not usable by cross-origin consumers. The preflight leg gets the same treatment, plus its own findings: a redirecting preflight, a failing preflight while simple GETs are allowed, dangerous methods on the allow-list, and a Max-Age over a day.
Fix in this order: stop reflecting the Origin, or drop credentials — that removes the critical error. Then add Vary: Origin to every response whose ACAO depends on the request's Origin. Then narrow Access-Control-Allow-Methods to the methods the API needs, and lower Access-Control-Max-Age to a day or less while you iterate. Re-check after each change with the foreign Origin: it should get no ACAO at all from a properly allowlisted API. And test each Origin you care about separately — a clean result for evil.example.com says nothing about the rest of your allowlist, because an allowlisting server answers each Origin differently by design. For the header set as a whole, the Security Headers Checker grades the rest of the response.
What the tool cannot see
Three honest limits. First, the tool sees what the server returns for the Origin it sent — not the allowlist itself. A server could allowlist a hundred origins and the checker would only learn about the one it tested (or that the tested one is not on it). Second, CORS is enforced by browsers, so the tool cannot tell you what a non-browser client would get: curl and server-to-server calls ignore CORS entirely, and a 'blocked' verdict never means the data is private. Third, the check is one Origin against one URL at one moment, from the checker's network location: a CDN can cache a CORS response with a stale ACAO, a load balancer can route the GET and the preflight to different origins, and the answer can vary by geography or header — re-check after a fix, on the URL your visitors actually hit.
The tool also cannot see the request side of the policy: whether your own pages ask for credentials correctly, whether your SameSite cookie settings would even send them, or whether a CSRF token would stop the request that CORS merely refuses to expose. CORS, CSRF tokens and SameSite cookies are three different defences for three different attacks, and a clean CORS result is not a clean bill of health for the others. Run the check on your own API with the CORS Misconfiguration Checker — and if it comes back reflected with credentials, treat it as the morning's first fix. To send test requests of your own — with the methods and headers your API actually expects — use the Webhook Tester.