Skip to content

updated Firebase CORS steps #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/troubleshooting/assets/uploadToGCC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,56 @@ Follow these steps to configure CORS for your Firebase Storage bucket:
3. **Run the following Command:**

```jsx
gcloud config set project <your-project-id>
gcloud config set project your-firebase-project-id;
```

4. **Navigate to your Firebase Storage bucket:**
4. **Define and upload your cors.json file:**

The `cors.json` file contains a list of origins that are allowed to access your resources. Each origin is a string that identifies a domain or port. For example, the following origin allows access from the domain `www.example.com`:

```jsx
cd gs://<your-bucket-name>
"origins": ["https://www.example.com"]
```

5. **Run the `cors` Command to Configure CORS:**
You can also specify a list of allowed headers. The following example allows access to the `Content-Type` and `Authorization` headers:

```jsx
gsutil cors set cors.json gs://<your-bucket-name>
"origins": ["https://www.example.com"], "allowedHeaders": ["Content-Type", "Authorization"]
```

You can also specify a list of allowed headers by running the following command:
To allow any origin to access your resource, you can use `*`. The `cors.json` file below allows any origin to access, but not modify your resources.

```jsx
gsutil cors set cors.json gs://<your-bucket-name> --allowed-headers="Content-Type, Authorization"
[
{
"origin": ["*"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
```

The `cors.json` file contains a list of origins that are allowed to access your resources. Each origin is a string that identifies a domain or port. For example, the following origin allows access from the domain `www.example.com`:
Once you have defined your `cors.json` file, upload it to Google Cloud Console.

```jsx
"origins": ["https://www.example.com"]
```
![](../assets/uploadToGCC.png)

You can also specify a list of allowed headers. The following example allows access to the `Content-Type` and `Authorization` headers:
To confirm that you have uploaded it correctly, you can run `ls` in your console and you should see your `cors.json` file listed.


5. **Run the `cors` Command to Configure CORS:**

```jsx
"origins": ["https://www.example.com"], "allowedHeaders": ["Content-Type", "Authorization"]
gcloud storage buckets update gs://your-google-storage-bucket-name --cors-file=cors.json
```

6. **(Optional) Confirm success by viewing the CORS of your bucket**

Run the following command to confirm that the rules from your `cors.json` file were applied.
```jsx
gcloud storage buckets describe gs://your-google-storage-bucket-name --format="default(cors_config)"
```
You should see the same allowed origins and any other info defined in your `cors.json` file.

For more information on configuring CORS in Firebase Storage, please see the **[official documentation](https://firebase.google.com/docs/storage/web/download-files#cors_configuration)**.