What is the syntax for multiple "match" statements in Firebase Storage security rules

Viewed 1607

I'm trying to create a photo folder in my default firebase storage bucket that allows public reads (and authenticated writes). All the examples show a single match statement, but what is the syntax for multiple match statements and what is the order of precedence when it matches multiple rules that overlap?

Does the order of the match statements matter, i.e. will the following not work since the allPaths match matches first before it would move on to the next match statement /photos? Or is it vice-versa in that it will read through all the match statements and the last statement supersedes anything before it? Is this syntax correct? Does it need a comma? Where is the documentation for the full syntax rules?

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }

    match /photos/{allPaths=**} {
      allow read;
      allow write: request.auth != null;
    }
  }
}

** Update**

Ok so I found the answer here

https://firebase.google.com/docs/storage/security/secure-files

The match syntax is valid and if they match more than one rule, they act as an OR so if either evaluates to true, it will be true.

1 Answers
service firebase.storage {
  match /b/{bucket}/o {
    match /images {
      // Exact match for "images/profilePhoto.png"
      match /profilePhoto.png {
        allow write: if <condition>;
      }
    }
  }
}

Docs

Related