Solved Error
How to Fix: 'blocked by CORS policy: No Access-Control-Allow-Origin header is present'
Quick Fix
If you control the backend, add the missing header to its responses (for example in Express: app.use(cors()), or manually set Access-Control-Allow-Origin: https://yourfrontend.com). If you do not control the backend, you cannot fix it from the browser side — instead route the request through your own backend proxy or server-side function.
1. Confirm it is really a CORS issue. Open DevTools > Network tab and check the failed request's response headers.
2. Add the correct header on the server for the exact origin (or * for public, credential-free APIs).
3. If it is a third-party API you do not control, call it from your own server/serverless function instead of directly from the browser.
What this error means
This is not really a network failure — the request usually reaches the server and gets a response. A CORS error occurs when your browser blocks a response because the server didn't include the required permission headers, even though the request often completes successfully on the server. CORS doesn't prevent requests — it prevents your JavaScript from reading the response.
Cross-Origin Resource Sharing (CORS) is a browser security mechanism that controls how web pages on one origin can request resources from a different origin, where an origin is defined by the combination of scheme, host, and port. The response to the CORS request is missing the required Access-Control-Allow-Origin header, which tells the browser whether the resource can be accessed by content operating within the current origin.
Important: CORS is enforced by the browser, but the fix is always on the server — the browser reads the response headers to decide whether your JavaScript is allowed to see the data, and no amount of frontend code can override a missing Access-Control-Allow-Origin.
Step-by-Step Guide
Fix 1: Confirm the request/response in DevTools first
- 1Open DevTools Network tab. Open the Network tab in your browser's DevTools before reproducing the error.
- 2Check response headers for
Access-Control-Allow-Origin. Click the failed request and check its Response Headers forAccess-Control-Allow-Origin. CORS errors in the browser console don't show the specific cause for security reasons — the Network tab is the only reliable place to see the actual headers exchanged. - 3Check for a preflight OPTIONS request. CORS relies on a mechanism by which browsers make a preflight request to the server, sending headers that indicate the HTTP method and headers that will be used in the actual request. If the OPTIONS request itself fails or is missing CORS headers, that is your root cause.
Fix 2: Add the header on your own server (if you control the backend)
- 1Add the
Access-Control-Allow-Originheader. Add the origin of the requesting site to the set of domains permitted access by adding it to theAccess-Control-Allow-Originheader's value, for exampleAccess-Control-Allow-Origin: https://example.com. - 2Use a wildcard only for public APIs. You can configure a site to allow any site to access it by using the
*wildcard, but you should only use this for public APIs — private APIs should never use*, and should instead have a specific domain or domains set. - 3For credentialed requests (cookies/auth), reflect the origin dynamically. To allow a site to make CORS requests without using the wildcard (for example, to enable credentials), your server must read the value of the request's Origin header and use that value to set
Access-Control-Allow-Origin, and must also set aVary: Originheader so caches don't serve the wrong origin's response to someone else. - 4Use the cors package in Node/Express. In Node/Express, use the official cors package:
app.use(cors({ origin: 'https://yourfrontend.com' }))rather than hand-writing headers. - 5Add CORS header to Apache configuration. In Apache, add a line to the server's configuration within the appropriate Directory, Location, Files, or VirtualHost section, typically in a
.conffile such ashttpd.conf, or in an.htaccessfile. - 6Never send more than one
Access-Control-Allow-Originheader. Browsers expect only oneAccess-Control-Allow-Originheader in a response — if a server returns multiple headers, the browser cannot determine which origin is allowed and blocks the request, so configure the server to return a single header that dynamically matches the request's origin.
Fix 3: Check for a preflight/method/header mismatch
- 1Verify allowed methods. The default cors package allows all methods like GET, POST, PUT, HEAD, PATCH; if you tighten security by specifying allowed methods, even if the origin matches, if the method is not allowed the preflight will fail and the actual request will be blocked.
- 2Verify custom headers in Access-Control-Allow-Headers. Check custom headers you're sending (like Authorization) are included in Access-Control-Allow-Headers on the server.
- 3Add
Access-Control-Expose-Headersif needed. If a custom response header reads as null in your JS, that's a different but related issue: by default browsers only expose a small set of CORS-safelisted response headers to JavaScript (Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, and Pragma) — any header outside that list is hidden unless the server explicitly opts in viaAccess-Control-Expose-Headers.
Fix 4: When you do NOT control the third-party server
- 1Accept that you cannot fix it client-side. If the remote server is not under your control and does not include the
Access-Control-Allow-Originheader, you cannot fix this error on the server side. - 2Build a small proxy/backend endpoint. Have your own server fetch the third-party API and return the data to your frontend — server-to-server requests are not subject to the browser's same-origin policy, since the restriction only applies to browser JavaScript.
- 3Use a browser extension only for local development, never in production. Extensions such as CORS-unblock tools work by injecting the header client-side, but this only works on your own machine and cannot be relied on for real users or production sites.
Fix 5: Local file (file://) or localhost quirks
- 1Run a local dev server instead of opening files directly. This error can occur when a request is made using a scheme other than HTTP or HTTPS, such as
file://— CORS policies apply only to HTTP(S) requests, so opening frontend files directly from your local filesystem can trigger this error, and running a local development server usually resolves it. - 2Treat
localhostand127.0.0.1as different origins. Origin is determined by protocol, domain, and port — even small differences likelocalhostvs127.0.0.1or different ports make the origin different. Make sure your allowed origin list matches exactly what the browser address bar shows.
When to get different help
Third-party/vendor API with no CORS support: contact that provider's support or check their docs for an officially supported proxy or SDK — you cannot force their server to add headers. Corporate or authenticated app with cookies breaking in Safari: this may be a browser privacy feature, not a config bug. Third-party cookie restrictions in Safari's ITP (Intelligent Tracking Prevention) can block credentialed CORS requests even with correct headers. Security review needed: if you are about to widen a CORS policy for a production API handling user data, avoid a blanket wildcard with credentials enabled and instead validate origins against an allowlist before shipping.
Sources:
- Reason: CORS header 'Access-Control-Allow-Origin' missing - HTTP | MDN
- Cross-Origin Resource Sharing (CORS) - MDN Web Docs
- Learn what causes CORS errors, how they impact your web app, and how to fix them securely with proper headers and backend configurations
- Four Common CORS Errors and How to Fix Them
- How to Fix Cross-Origin Errors — CORS Error Explained
- Common CORS errors and how to fix them — WorkOS
- 3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works
- How to Fix 'No Access-Control-Allow-Origin Header Present'
Heads up: this guide was drafted with AI assistance from the real sources listed below, and structured by our team for clarity. It may not cover every possible cause — if it doesn't fix your issue, let us know and we'll take a closer look. See how we create our fixes.
Was this fix helpful?
Related Error Fixes
- How to Fix: pip 'Could not build wheels for ...' ErrorPython
- How to Fix: "Cannot read properties of undefined (reading '...')"JavaScript
- How to Fix: ModuleNotFoundError: No module named '...'Python
- How to Fix Git Error: "refusing to merge unrelated histories"Git
- How to Fix: Docker Desktop 'WSL 2 installation is incomplete'Docker