What CORS does, in one paragraph
Browsers stop a page on one website from reading responses from another website, unless that other website says it's allowed. CORS (cross-origin resource sharing) is how your API says it. When a page on other-site.example calls your API, the browser checks your response for an Access-Control-Allow-Origin header and only lets the page read the answer if that header allows other-site.example. MDN's CORS guide explains the full rules.
Two things follow. CORS protects your users' browsers, not your server; tools like curl ignore it completely. And CORS is only as safe as the decision your server makes about which sites to allow.
When "*" is fine
Access-Control-Allow-Origin: * means "any website may read this". For data that's public anyway (a product list, public posts, a status page), that's fine: anyone could fetch it without a browser.
The browser itself limits the wildcard. MDN's guide says a credentialed request (one that sends cookies or other login data) is blocked if the response uses *: the server has to name an explicit site. So * on its own can't leak a signed-in user's data through cookies.
The dangerous version: reflecting any origin with credentials
The real problem appears when a developer, or an AI builder, wants cookies to work across sites and hits that rule. The quick "fix" is to copy whatever Origin the request came with into Access-Control-Allow-Origin and add Access-Control-Allow-Credentials: true. Now every website is "allowed", with your users' cookies.
What that means in practice: a user signed in to your app visits any other page on the internet. That page quietly calls your API; the browser attaches the user's cookies; your API answers with their profile, messages or orders; and the other page can read it. The user sees nothing.
Look-alike mistakes do the same damage:
- Allowing the
nullorigin. Sandboxed frames and some local files sendOrigin: null, and any site can create one. - Loose matching. An allow list that checks "ends with yourapp.com" also accepts
evilyourapp.com; "starts with" acceptsyourapp.com.evil.example. Compare full origins exactly. - Trusting every subdomain. If any subdomain can be taken over or hosts user content, it inherits your API's trust.
OWASP's HTML5 security cheat sheet gives the same advice: allow only specific trusted domains, never wildcards or a blindly reflected Origin, and don't treat CORS as access control.
How to set it safely
- Same site, no CORS needed. If your front end and API share one origin, you don't need CORS headers at all. Leave them off.
- Different origins you own: keep a short list of exact origins (with
https://), compare the request'sOriginagainst it, and only then send it back with credentials allowed. SendVary: Originso caches don't mix answers up. - Public, read-only data:
*is fine, without credentials. - Never rely on CORS alone. Every endpoint still checks who's signed in and what they may see. CORS decides who may read a response in a browser; it doesn't stop a request from reaching your server.
A prompt you can give your builder: "Set CORS to an exact allow list of our own origins. Never reflect the request's Origin, never allow the null origin, and only allow credentials for origins on the list."
Check your own API
From a terminal, send a request with a made-up origin and look at the response headers:
curl -s -D - -o /dev/null -H "Origin: https://not-my-site.example" https://your-app.example/api/me
If the answer contains Access-Control-Allow-Origin: https://not-my-site.example together with Access-Control-Allow-Credentials: true, any website can read that endpoint as your signed-in users. Try Origin: null the same way. Check the endpoints that return personal data, not just the home page.
What Securick checks
The free scan sends requests from made-up origins to your site and its API addresses and reads the CORS answer, among its 46 tests:
- #29 Not open to every website Free
- #30 Not open to every website with login cookies Free
- #31 Error pages hide code details Free
It only reads headers; it never signs in as anyone or reads their data.
Questions
My API uses a token in the Authorization header, not cookies. Does CORS still matter?
Less. Another site can't read your user's token, so it can't attach it. A reflected origin is still worth fixing, because it's easy to add cookies later and forget why the setting was there.
Why does my builder keep suggesting Access-Control-Allow-Origin: *?
It's the quickest way to make a cross-site request work during development. It's fine for public data; for signed-in features, replace it with an exact list of your own origins.
Does a strict CORS setting stop attacks on my server?
No. CORS only tells browsers who may read responses. Scripts and tools can still send requests, so every endpoint has to check sign-in and permissions itself.