CORS error: "blocked by CORS policy"
CORS is a rule enforced by the browser, not by your API: a page from one origin may read a response from another origin only if the response says so with Access-Control-Allow-* headers. Your API often works in curl or Postman and fails in the browser for exactly this reason. Answer the questions to find which header is missing. The fix is almost always on the server, not in the front-end code.
Find your cause
All the causes and fixes
This is not CORS: the request did not reach a server
- Check the URL, DNS, TLS certificate, mixed content (an http API called from an https page) and ad blockers or VPN. The browser shows a CORS-like message when a network error happens.
- Test the URL directly in the browser address bar or with curl.
The preflight is rejected by authentication
- The browser sends the OPTIONS preflight without your Authorization header or cookies. If your gateway or middleware requires a token on every method, the preflight gets 401 or 403 and the real call is never made.
- Let OPTIONS requests through before the authentication step, or handle CORS in a layer that runs first.
- In WSO2 API Manager and most gateways, enable the built-in CORS configuration for the API instead of authenticating OPTIONS.
OPTIONS is not handled
- The route or framework returns 404 or 405 for OPTIONS. Add a handler, or enable your framework's CORS middleware, which answers preflights automatically.
- A reverse proxy or API gateway may also block OPTIONS: allow it.
A request header is not allowed
- Headers such as Authorization, or Content-Type other than form types and text/plain, make the request "non-simple" and trigger a preflight. The server must list them in
Access-Control-Allow-Headers. - Add the exact header names you send (case-insensitive), for example
Authorization, Content-Type. - A custom header added by a library (for example a trace or correlation ID) is a common surprise: look at the preflight's Access-Control-Request-Headers.
The method is not allowed
- Put the methods you use in
Access-Control-Allow-Methods(GET, POST, PUT, PATCH, DELETE, OPTIONS). Only GET, HEAD and POST are allowed without a preflight, and even those can trigger one if headers are unusual.
The response has no CORS headers
- Add
Access-Control-Allow-Originwith the exact origin of your front-end (scheme + host + port, no path), or * for public data without credentials. - The headers must be on the actual response and also on error responses (401, 404, 500): a server error without CORS headers appears as a CORS error and hides the real status.
- Check that a gateway, CDN or proxy does not strip the headers or cache a response made for another origin.
Wildcard origin cannot be used with credentials
- If the request includes credentials,
Access-Control-Allow-Origin: *is refused by the browser. Return the specific origin instead (from an allow-list, never by blindly echoing the request's Origin) and addAccess-Control-Allow-Credentials: true. - The same rule applies to * in Allow-Headers and Allow-Methods for credentialed requests.
Access-Control-Allow-Credentials is missing
- For requests with cookies or HTTP authentication the response must contain
Access-Control-Allow-Credentials: true, and the origin must be exact.
Caching mixes responses for different origins
- If the server returns a different Access-Control-Allow-Origin for different origins, it must add
Vary: Origin, otherwise a cache can serve a response made for another origin and the browser rejects it, intermittently. - Check CDN and gateway caching rules for responses with CORS headers.
Frequently asked questions
Why does my API work in Postman or curl but not in the browser?
Postman and curl do not enforce CORS. The browser enforces it to protect users, so the API must send the right Access-Control headers for browser clients.
Can I fix CORS in my front-end code?
No. The server (or gateway) must send the headers. A front-end workaround is either a proxy on your own domain or a no-cors request, which gives you an unreadable (opaque) response.
Is Access-Control-Allow-Origin: * safe?
For public, read-only data without credentials it is common. For anything with cookies or tokens use an allow-list of exact origins.
About this page
Nothing you select here is sent anywhere: the questions run in your browser. If you paste anything into the related tools, read their privacy notes and use test data. See the privacy notice.
Related: HTTP request tester with CORS diagnosis · HTTP status codes · OAuth2 error doctor · All error guides
We configure and review OAuth2/OIDC and API gateways, including WSO2 Identity Server and API Manager. See the WSO2 services or the security review.
Message us on LinkedIn