Firefox blocks a cross-origin request even though the CORS headers are set
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resourceShort answer
Firefox puts a Reason in the console message, and that text is the diagnosis. With headers present, the usual causes are two Access-Control-Allow-Origin values, an origin that does not match exactly, a preflight that lacks a header the request sends, a cross-origin redirect, or a request that never completed.
Fix it fast
1Find out which cause you have
Read the Reason in the Firefox console and send the same request with curl while pretending to be your site. The headers in the output show which section below applies.
curl -i -H "Origin: https://app.example.com" https://api.example.com/resource2Match what you see, then jump to its fix
- 1
Reason: Multiple CORS header 'Access-Control-Allow-Origin' not allowedTwo Access-Control-Allow-Origin headers are sentFix - 2
Reason: CORS header 'Access-Control-Allow-Origin' does not matchThe allowed origin does not match the page originFix - 3
Reason: missing token 'authorization' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channelThe preflight answer does not list a header the request sendsFix - 4
Reason: CORS request external redirect not allowedThe URL redirects to another originFix - 5
Reason: CORS request did not succeedThe request never completed, so no headers arrivedFix
- 1
What does the error look like?
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resourceReason: Multiple CORS header 'Access-Control-Allow-Origin' not allowedReason: CORS header 'Access-Control-Allow-Origin' does not matchReason: missing token in CORS header 'Access-Control-Allow-Headers' from CORS preflight channelReason: CORS request did not succeed
Cause 1 of 5
Two Access-Control-Allow-Origin headers are sent
1Check
The app and a proxy, load balancer or CDN each add the header, or a CORS middleware is registered twice. The curl output shows the header twice.
curl -sI -H "Origin: https://app.example.com" https://api.example.com/resource | grep -i access-control-allow-origin2Fix
Let exactly one layer set it. In nginx, drop the backend's copy before adding your own.
location /api/ {
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Origin "https://app.example.com" always;
proxy_pass http://backend;
}3Verify
Run the curl command again and confirm one line.
curl -sI -H "Origin: https://app.example.com" https://api.example.com/resource | grep -ic access-control-allow-originConfirmed by developer.mozilla.org
Cause 2 of 5
The allowed origin does not match the page origin
1Check
An origin is scheme, host and port. A trailing slash, http versus https, or a different port makes the value wrong, and so does a list of several origins in one header.
# compare the page's origin with the header value
console.log(location.origin)2Fix
Echo back the request's Origin when it is on your allow list, and add Vary: Origin.
const allowed = ["https://app.example.com", "http://localhost:3000"];
app.use((req, res, next) => {
const origin = req.headers.origin;
if (allowed.includes(origin)) {
res.setHeader("Access-Control-Allow-Origin", origin);
res.setHeader("Vary", "Origin");
}
next();
});3Verify
Repeat the curl command and compare the header with the Origin you sent.
curl -sI -H "Origin: https://app.example.com" https://api.example.com/resource | grep -i access-control-allow-originConfirmed by developer.mozilla.org
Cause 3 of 5
The preflight answer does not list a header the request sends
1Check
A request with Authorization, a custom header or a JSON content type triggers an OPTIONS preflight. Every header the request sends must be in the preflight's Access-Control-Allow-Headers, and the OPTIONS call needs a successful response.
curl -i -X OPTIONS -H "Origin: https://app.example.com" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: authorization,content-type" https://api.example.com/resource2Fix
Add the missing header names to the allowed list, and make sure OPTIONS is answered before any auth middleware.
app.use(cors({
origin: "https://app.example.com",
allowedHeaders: ["Content-Type", "Authorization"],
}));3Verify
Repeat the OPTIONS call and look for the header names in the response.
curl -si -X OPTIONS -H "Origin: https://app.example.com" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: authorization" https://api.example.com/resource | grep -i allow-headersConfirmed by developer.mozilla.org
Cause 4 of 5
The URL redirects to another origin
1Check
A CORS request that receives a 301, 307 or 308 redirect to a different origin is blocked.
curl -sI https://service.example.com/data | grep -i -E "^HTTP|^location"2Fix
Call the final URL the redirect points to, so the request no longer redirects.
const res = await fetch("https://other.example.net/data");3Verify
The request returns without a redirect and the data is readable.
curl -sI https://other.example.net/data | head -n 1Confirmed by developer.mozilla.org
Cause 5 of 5
The request never completed, so no headers arrived
1Check
This is a network-level failure, not a header problem. Ad blockers and privacy tools, DNS or connection errors, a bad certificate, mixed content, or a server that answers the preflight but not the real request all cause it.
# Firefox DevTools > Network: look at the failed request's status and security tab2Fix
Try a private window with extensions off, fix any certificate or mixed-content problem, and check the server answers the real request.
# open a private window, then retry the request3Verify
The request now shows a status code in the Network panel.
# reload and check the Network panelConfirmed by developer.mozilla.org
How do I stop it coming back?
- Set CORS headers in one place only, and write the allowed origins as a list in code.
- Test with curl and an Origin header before testing in a browser.
- Answer OPTIONS requests before authentication runs.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
Related fixes
Web apps
Axios sends no cookie to an Express API even with withCredentials set to true
The login response has a Set-Cookie header, but the browser stores nothing
withCredentials only tells the browser to attach cookies.
4 causes, each with a fixWeb apps
The cors-anywhere.herokuapp.com demo proxy stopped working
Missing required request header. Must specify one of: origin,x-requested-with
The public cors-anywhere.herokuapp.com server is only a demo, is rate limited, and since February 2021 requires an opt-in.
2 causes, each with a fixWeb apps
The browser blocks your API response: no Access-Control-Allow-Origin header
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.example.com/orders. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
The browser received the response but refused to hand it to your script, because it did not carry an Access-Control-Allow-Origin header naming the page's origin.
4 causes, each with a fixWeb apps
The browser rejects the CORS preflight because the OPTIONS reply is not a 2xx
The request in the Network tab is an OPTIONS call with a red status, and the real GET or POST never appears
Before some cross-origin calls the browser sends an OPTIONS preflight and treats any answer outside 200 to 299 as a network error.
3 causes, each with a fixWeb apps
A public website cannot reach your local dev server: local network request blocked
Look for and connect to any device on your local network
Chrome treats a request from a public website to localhost or a private IP as a local network request.
3 causes, each with a fixWeb apps
CORS fails when you open an HTML file straight from disk
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///
A page opened from disk has an opaque origin, so browsers treat every request it makes as cross-origin, and CORS only works over http or https.
3 causes, each with a fix