Home > other >  Firebase Storage: Public to Internet about files under a specific directory
Firebase Storage: Public to Internet about files under a specific directory

Time:10-31

I want to publish all the files under a specific directory to the Internet.

Security Rules

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /public/{allPaths=**} {
      allow read;
      allow write: if request.auth != null;
    }
  }
}

After writing the security rules as described above, when I open the Browser of Cloud Storage:

  • The files under the directory are still set to private.
  • If you look at the details of each file, you will see that no public URL has been issued.

enter image description here

And when I enter the Authenticated URL, you will be redirected to Google's login page.

How can I fix this?

CodePudding user response:

Firebase security rules only control who can get the URL of a specific object either by Firebase SDK or REST APIs. If you check for object URL in Firebase console, you'll see an URL of format which is probably what you are looking for:

https://firebasestorage.googleapis.com/v0/b/[PROJECT].appspot.com/o/public/dog.jpg?alt=media&token=fd991fdf-a33f-4321-9017-09907e1a5243

Security rules can only restrict users from getting this URL at first place however anyone with this URL can access the image/file (if an authorized user has shared the URL).

That being said, the rule allow read: if true; will allow anyone to get the public (like the one shown above) and they can access it.


If you want a public link from GCS as well then you would have to edit permissions from GCP console and allow allUsers to read it:

enter image description here

  • Related