【问题标题】:Firestore security rules, nested fieldFirestore 安全规则,嵌套字段
【发布时间】:2017-10-26 18:37:11
【问题描述】:

我们的数据库结构如下:

trips
   12345
      toArea
         radius: 150
         name: "citycenter"
   54321
      toArea
         radius: 250
         name: "main street"

我们尝试创建一些从文档中读取的规则:

match /chats/{trip} {
    match /messages/{message} {
       allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea != null
    }
}

一切正常

但下一条规则不起作用:

allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea != null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea.radius != null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea.radius == null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea["radius"] == null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea["radius"] != null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data["toArea.radius"] == null
allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data["toArea.radius"] != null

我真的不明白它有什么问题,两个相反的规则(==null / != null)怎么会不起作用。我们如何管理规则中的字段 toArea.radius

【问题讨论】:

  • 试试.data.toArea.data.radius
  • 我们目前在规则中遇到嵌套属性问题,这几乎绝对不是您的错。我们正在尽快推出修复程序,感谢您的耐心等待!
  • 会一直是.data.field.data吗?

标签: firebase-security google-cloud-firestore


【解决方案1】:

编辑(2017 年 12 月 18 日):这些现在都已修复,所以这应该只是工作™。

正如@hatboysam 所提到的,您目前遇到了两个我们正在快速修复的错误:

  1. get().data 仅在您的规则中某处引用 resource.datarequest.resource.data 时才有效(我们曾经支持 get() 在不使用 data 的情况下返回 resource,但这最终会出现问题,因此已更改就在发布之前)。
  2. 嵌套属性(例如toArea.radius)已损坏。

1 很容易解决:

match /chats/{trip} {
    match /messages/{message} {
       allow read, write: if get(/databases/$(database)/documents/trips/$(trip)).data.toArea != null
    }
}
match /bogusPathThatWillNeverMatch {
  allow read: if resource.data != null; // should never be true
}

1 和 2 都将很快修复,敬请期待解决方案。

【讨论】:

  • 您能否指出我们可以订阅关于此问题的更新的错误跟踪器的方向,@mike-mcdonald? :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-13
  • 1970-01-01
相关资源
最近更新 更多