Firebase安全规则通配符 [语法版本2] 问题

huangapple go评论62阅读模式
英文:

Firebase Security rules wildcards [syntax version 2] question

问题

我阅读了Firebase安全规则的官方文档。但我遇到了一段难以理解的文本。请确认我是否正确理解了以下引用:

在安全规则的第2版中,递归通配符匹配零个或多个路径项。match/cities/{city}/{document=**}匹配任何子集合中的文档,以及cities集合中的文档。您必须通过在安全规则顶部添加rules_version = '2'来选择第2版:

rules_version = '2';
service cloud.firestore {
   match /databases/{database}/documents {
      // 匹配cities集合中的任何文档,以及任何子集合中的文档。
      match /cities/{city}/{document=**} {
         allow read, write: if <condition>;
      }
   }
}

这段引用来自这个页面

问题

如果我正确理解了这个引用:

在安全规则的第2版中,递归通配符匹配零个或多个路径项。

那么这个引用的意思是:match/cities/{city}/{document=**}将匹配到请求中的/cities/LA/cities/LA/landmarks/landmark1路径。因为在/cities/LA示例中,递归通配符匹配零个路径项,如上述引用所述。

英文:

I read the official documentation of Firebase Security Rules. But I came across a text that was hard to understand. Please confirm if I understood the following quote correctly

> In version 2 of the security rules, recursive wildcards match zero or
> more path items. match/cities/{city}/{document=**} matches documents
> in any subcollections as well as documents in the cities collection.
> You must opt-in to version 2 by adding rules_version = &#39;2&#39;; at the top
> of your security rules:
>
> rules_version = '2';
> service cloud.firestore {
>   match /databases/{database}/documents {
>     // Matches any document in the cities collection as well as any document
>     // in a subcollection.
>     match /cities/{city}/{document=**} {
>       allow read, write: if <condition>;
>     }
>   }
> }
This quote from this page

Question

If I understood correctly this quote:
> In version 2 of the security rules, recursive wildcards match zero or
> more path items. match/cities/{city}/{document=**} matches documents
> in any subcollections as well as documents in the cities collection.

That quote means: that match/cities/{city}/{document=**} matches to /cities/LA and /cities/LA/landmarks/landmark1 paths in requests. Because in /cities/LA example recursive wildcards match to zero as said doc quote:
> In version 2 of the security rules, recursive wildcards match zero or
> more path items.

答案1

得分: 1

那句话的意思是:match/cities/{city}/{document=** 与请求中的路径 /cities/LA/cities/LA/landmarks/landmark1 匹配。因为在 /cities/LA 的示例中使用了递归通配符。

是的,这正是它的作用。您可以从 cities 集合中读取文档,还可以从 landmarks 子集合中读取文档。递归通配符意味着您的安全规则将允许您读取来自顶级集合的文档,并会延伸到最深层的子集合。

英文:

> That quote means: that match/cities/{city}/{document=** matches to /cities/LA and /cities/LA/landmarks/landmark1 paths in requests. Because in /cities/LA example recursive wildcards.

Yes, that is exactly what it does. You can read documents from the cities collection, as well as from the landmarks sub-collection. Recursive wildcards mean that your security rules will allow you to read documents from the top-level collection and will fall to the deepest sub-collections.

huangapple
  • 本文由 发表于 2023年7月27日 21:48:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定