Browser blocks a Firebase Storage request at the CORS preflight
Response to preflight request doesn't pass access control check: It does not have HTTP ok statusShort answer
A browser sends an OPTIONS preflight before some cross-origin requests, and Cloud Storage answers it only from the CORS configuration on the bucket. If the bucket has none, or it does not list your origin, method or headers, the browser blocks the call. Write a cors.json and apply it to the bucket.
Fix it fast
1Find out which cause you have
Print the CORS configuration that is on the bucket now. An empty result means the bucket has none.
gcloud storage buckets describe gs://BUCKET_NAME --format="default(cors_config)"2Match what you see, then jump to its fix
- 1
The describe command above shows no cors_configThe bucket has no CORS configurationFix - 2
A configuration is listed, yet the browser still blocks the requestThe file exists, but origin, method or headers do not match the requestFix - 3
The configuration is correct but the URL host is storage.cloud.google.com, or you rely on the JSON APIThe request goes to an endpoint that does not read the bucket configurationFix
- 1
What does the error look like?
Response to preflight request doesn't pass access control check: It does not have HTTP ok status
Cause 1 of 3
The bucket has no CORS configuration
1Check
Without a matching configuration the XML API returns no CORS headers, and the browser fails the request.
gcloud storage buckets describe gs://BUCKET_NAME --format="default(cors_config)"2Fix
Create cors.json, then apply it. For plain downloads from the web the Firebase docs use a GET-only file; list your real origin instead of * if you can.
# cors.json
[
{
"origin": ["https://example.com"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
gcloud storage buckets update gs://BUCKET_NAME --cors-file=cors.json
# the Firebase docs use the older gsutil form:
gsutil cors set cors.json gs://BUCKET_NAME3Verify
Describe the bucket again and see your origin in the output, then reload the page and repeat the request.
gcloud storage buckets describe gs://BUCKET_NAME --format="default(cors_config)"Confirmed by docs.cloud.google.com
Cause 2 of 3
The file exists, but origin, method or headers do not match the request
1Check
Compare the page's exact origin (scheme, host and port) and the request method with the file. A preflight is sent for methods other than GET, HEAD or POST, for unusual POST content types and for custom headers. If any of them is not allowed, the browser never sends the main request.
gcloud storage buckets describe gs://BUCKET_NAME --format="default(cors_config)"2Fix
Add the missing origin and method, and put every custom request header in responseHeader, then apply the file again.
[
{
"origin": ["https://example.com", "http://localhost:5173"],
"method": ["GET", "PUT", "POST"],
"responseHeader": ["Content-Type"],
"maxAgeSeconds": 3600
}
]3Verify
Apply the file and watch the OPTIONS request in the browser's network tab: it now returns the allow headers.
gcloud storage buckets update gs://BUCKET_NAME --cors-file=cors.jsonConfirmed by docs.cloud.google.com
Cause 3 of 3
The request goes to an endpoint that does not read the bucket configuration
1Check
Only the XML API endpoints (storage.googleapis.com/BUCKET_NAME or BUCKET_NAME.storage.googleapis.com) apply the bucket CORS configuration. storage.cloud.google.com does not allow CORS requests at all.
# read the host in the failing request URL in the network tab2Fix
Request the object through an XML API URL, as in the example below.
https://storage.googleapis.com/BUCKET_NAME/path/to/file.png3Verify
The request now returns an Access-Control-Allow-Origin header for your origin.
curl -s -I -H "Origin: https://example.com" https://storage.googleapis.com/BUCKET_NAME/path/to/file.pngConfirmed by docs.cloud.google.com
How do I stop it coming back?
- Keep cors.json in the repository and apply it from a documented step, so a new bucket does not go live without it.
- List real origins, including your local dev address, instead of * where you can.
- Re-read the bucket configuration after every change to the domain or port.
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:
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Web apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fixWeb apps
A POST to a Google Apps Script web app returns 405 or a CORS error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.
3 causes, each with a fixWeb 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
A Chrome extension content script cannot read another site's response
Access to fetch at 'https://api.example.com/price' from origin 'https://shop.example.net' has been blocked by CORS policy
Since Chrome 85 a content script's request is treated as a request from the web page it runs in, so the page's CORS rules apply and the extension's host permissions do not help.
3 causes, each with a fixWeb apps
A web font served through CloudFront is blocked by CORS
Reason: CORS header 'Access-Control-Allow-Origin' missing
Browsers load web fonts with a CORS request, so the font response must carry Access-Control-Allow-Origin.
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 fix