The short answer
A CORS error means a web page asked the browser to call a different site, and that site did not tell the browser the page was allowed to read the answer. The browser enforces the rule, the server grants the permission, and the fix is almost always a response header on the server - not a change to the page making the call.
Access to fetch at 'https://api.example.com/orders' from origin 'https://app.example.com'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present
on the requested resource.That is also why the same request works from curl, Postman or your backend: none of them is a browser, so none of them applies the rule.
What the browser is protecting
Browsers send your cookies along with requests to the site that set them. Without a restriction, any page you visit could call your bank or your company's admin panel with your session and read what came back. The same-origin policy stops that: by default a page can read responses only from its own origin.
An origin is the scheme, host and port together. All three must match:
| Page at https://app.example.com calls | Same origin? | Why |
|---|---|---|
https://app.example.com/api/orders | Yes | Only the path differs |
http://app.example.com/api | No | Different scheme |
https://api.example.com/orders | No | Different host - a subdomain counts |
https://app.example.com:8443/api | No | Different port |
http://localhost:3000 calling http://localhost:8080 | No | Different port |
CORS - cross-origin resource sharing - is the way a server opts out of that default for callers it chooses. It loosens a restriction; it is not a security feature you add to an API, and it does not stop anyone calling the API from outside a browser.
Simple requests: sent, then blocked
For a plain GET, or a POST with a form-style content type and no custom headers, the browser sends the request straight away with an Origin header and checks the response:
GET /orders HTTP/1.1
Host: api.example.com
Origin: https://app.example.com
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://app.example.com
Content-Type: application/jsonIf Access-Control-Allow-Origin is missing or names a different origin, the page gets an error instead of the response. Note what that means: the server received the request and ran it. CORS stopped the page from reading the result, not the request from happening. That is why CORS is no substitute for authentication or CSRF protection.
Preflight: the OPTIONS request you did not write
Anything beyond a simple request - a PUT, PATCH or DELETE, a JSON body (Content-Type: application/json), or a header such as Authorization - makes the browser ask permission first, with an OPTIONS request called a preflight:
OPTIONS /orders/42 HTTP/1.1
Host: api.example.com
Origin: https://app.example.com
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: authorization
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, DELETE
Access-Control-Allow-Headers: authorization, content-type
Access-Control-Max-Age: 600Only if the answer allows the method and every header does the browser send the real request - and the real response must carry Access-Control-Allow-Origin too. Access-Control-Max-Age lets the browser remember the answer, here for ten minutes, so it does not preflight every call.
Preflights fail in ways that have nothing to do with your handler: the server or a gateway in front of it returns 404 or 405 for OPTIONS, or an authentication layer answers 401 because the preflight carries no credentials - browsers never send cookies or Authorization on a preflight. Let OPTIONS through before authentication runs.
Reading the error message
| The console says | What is wrong | Fix on the server |
|---|---|---|
No Access-Control-Allow-Origin header is present | The response has no CORS header at all - often an error page from a proxy or a crashed handler | Send the header on every response, including errors |
| The header has a value that is not equal to the supplied origin | The server allows a different origin, often with or without www, or http instead of https | Echo the exact origin, with scheme and no trailing slash |
| Response to preflight request does not pass access control check | The OPTIONS request was refused or redirected | Answer OPTIONS with 2xx and the CORS headers, before auth |
| Request header field authorization is not allowed | The header is missing from Access-Control-Allow-Headers | List every custom header the page sends |
| Method PUT is not allowed | The method is missing from Access-Control-Allow-Methods | List it |
The value must not be the wildcard * when credentials mode is include | Cookies or HTTP auth are being sent to a server that answers * | Name the origin and add Access-Control-Allow-Credentials: true |
Multiple values in Access-Control-Allow-Origin | Both the app and a proxy added the header | Set it in one place only |
Cookies and credentials
By default a cross-origin fetch sends no cookies. To send them the page asks with credentials: "include", and the server has to agree twice over:
Access-Control-Allow-Originmust name the exact origin. The wildcard*is refused when credentials are involved.Access-Control-Allow-Credentials: truemust be present.- The cookie itself must be allowed cross-site:
SameSite=None; Secure. Otherwise the browser does not attach it, and CORS is not the cause.
A server that allows several origins should read the request's Origin, check it against a list, and echo it back - together with Vary: Origin, so a cache does not hand one origin's response to another. Never echo the origin back unchecked while also allowing credentials: that gives every website access to your users' sessions.
Headers the page cannot see
Even on an allowed response, JavaScript can read only a short list of response headers, such as Content-Type and Cache-Control. Anything else - a pagination Link header, X-Request-Id, WWW-Authenticate - has to be listed by the server in Access-Control-Expose-Headers. If a header is visible in the browser's Network tab and missing in your code, this is why.
Fixes that are not fixes
mode: "no-cors"does not bypass anything. It lets the request go out and gives you an opaque response whose status, headers and body you cannot read.- A browser extension or a flag that disables CORS changes your browser only. Your users still get the error.
- Adding
Access-Control-Allow-Originas a request header does nothing. It is a response header, and sending it from the page only adds another header for the preflight to reject. - A public "CORS proxy" works by sending your requests, tokens included, through someone else's server.
What does work, when you cannot change the API:
- Call it from your own backend, which is not subject to CORS, and have the page call your backend.
- In development, use your dev server's proxy (Vite, Angular CLI and webpack all have one) so the page and the API appear to share an origin.
- Serve the API and the page from the same origin in production, for example behind one reverse proxy.
Debugging one, step by step
- Open the Network tab and find the failing request. If there is an
OPTIONSentry just before it, look at that one first. - Check its status. Anything other than 2xx on the preflight is the problem, whatever the console message says.
- Read the response headers and compare
Access-Control-Allow-Originwith the page's origin, character for character. - Send the same request with curl and an
Originheader to see exactly what the server answers, without the browser in the way. - If only some requests fail, compare a working and a failing one: usually the failing one adds a header or uses a method the server does not list.
The API client on this site is a web page, so it is subject to the same rule. Its requests come from the origin https://oktools.dev, which makes it a quick test of whether an API allows any origin; an API that allows only your own site will refuse it, correctly. To share what you saw with whoever runs the API, export the session from the Network tab and check it in the HAR viewer, which can remove cookies and tokens before you send it.
