Firestore安全规则,嵌套字段

问题描述 投票:1回答:1

我们的数据库结构如下:

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)怎么可能不起作用。我们如何在规则中使用torea.radius字段进行管理?

firebase-security google-cloud-firestore
1个回答
2
投票

编辑(12/18/17):这些都已修复,所以这应该是Just Work™。

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

  1. get().data只有在你的规则中某处提到resource.datarequest.resource.data才有效(我们曾经支持get()在不使用resource的情况下返回data,但这最终会产生问题,所以它在发布前就已经改变了)。
  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都将很快修复,敬请期待分辨率。

© www.soinside.com 2019 - 2024. All rights reserved.