How to Fix CORS Errors in Firebase Storage (Including Firebase Studio)

If you’ve built something in Firebase Studio or Firebase Hosting and tried to access files in Firebase Storage, you’ve probably seen the dreaded:
Access to fetch at ‘https://firebasestorage.googleapis.com/...' from origin ‘https://your-site.com’ has been blocked by CORS policy
This happens because Firebase Storage (which is really a Google Cloud Storage bucket) blocks requests from other websites unless you explicitly allow them using a CORS (Cross-Origin Resource Sharing) configuration.
Firebase Studio makes it easy to upload and host files, but it doesn’t automatically configure CORS for you. If you’re trying to serve images, videos, JSON files, or other assets to your site, you need to set this up manually.
This guide walks you through how to fix Firebase Storage CORS errors, specifically for projects built in Firebase Studio or Firebase Hosting.
Why CORS Errors Happen in Firebase Studio & Firebase Storage
CORS exists for security. Without it, any site could make requests to your Firebase Storage bucket and access potentially sensitive files.
When you create a project in Firebase Studio and upload files to Firebase Storage, those files live in a Google Cloud Storage bucket. By default, that bucket only allows direct access from the same origin. Your React app, static HTML site, or even another Firebase Hosting site will be blocked unless you add your site’s domain to the CORS configuration.
Step 1: Install gsutil
gsutil
is Google’s command-line tool for managing Cloud Storage (and by extension, Firebase Storage).
Official instructions: Install gsutil
If you don’t have it yet, install via Google Cloud SDK:
|
|
Step 2: Log In to Your Firebase Account
Once installed, log in:
|
|
Select the Google account linked to your Firebase Studio project.
Then set the active project:
|
|
Tip: You can find YOUR_PROJECT_ID
in Firebase Console → Project Settings → General.
Step 3: Find Your Firebase Storage Bucket Name
Firebase Storage buckets usually follow this format:
PROJECT_ID.appspot.com
Example:
If your project ID is my-firebase-studio-app
, your bucket will be:
my-firebase-studio-app.appspot.com
To confirm:
|
|
Step 4: Create Your cors.json
File
This JSON file tells Firebase Storage which domains can access your files.
Basic example for a single site:
|
|
Allowing Multiple Methods
If you need uploads, deletions, or updates from your site:
|
|
Allowing All Origins (For Testing)
For quick testing, you can allow *
(but don’t use in production):
|
|
⚠️ Warning: This allows anyone to make requests to your bucket.
Step 5: Apply the CORS Rules to Your Firebase Storage Bucket
Run:
|
|
Example:
|
|
Step 6: Test Your Firebase Studio CORS Fix
Once applied, reload your site and try fetching from Firebase Storage again.
If you still see CORS errors:
- Make sure your exact site domain (including
https://
) is incors.json
- Clear your browser cache — CORS results can be cached
- Double-check you updated the right bucket
Common Firebase Studio CORS Issues
- Wrong Bucket Name – Firebase Studio can use multiple buckets if you’ve enabled multi-region storage. Always check with
gcloud storage buckets list
. - Missing Methods – If your front end uploads files but your CORS config only allows
"GET"
, uploads will fail. - Using
localhost
in Development – Add"http://localhost:3000"
(or whatever your dev port is) to the"origin"
list for local testing. - Mixing Firebase Hosting & Storage – Just because your files are served via Firebase Hosting doesn’t mean they skip CORS rules if they live in Firebase Storage.
TL;DR — Quick Fix for Firebase Studio CORS Errors
Install gsutil
Find your Firebase Storage bucket name
Write
cors.json
with your allowed originsRun:
1
gcloud storage buckets update gs://YOUR_BUCKET_NAME --cors-file=cors.json
Test and adjust methods/origins as needed.
✅ That’s it — your Firebase Studio project should now be able to serve files from Firebase Storage without CORS errors.