【问题标题】:Firebase security rules protect list and public objectFirebase 安全规则保护列表和公共对象
【发布时间】:2016-03-01 10:22:35
【问题描述】:

只有当您拥有键值时,我才有可以公开访问的服务器列表。

基本上如果用户有对象键,那么他可以检索完整的子对象。但不应允许他访问对象列表。

对象示例

{
    "servers": { // list of server

        // list should not be access directly - no anonymous access

        "key1": {  // this object can be access anonymously, if user knows the key
            "name": "linux"
            //...
        },

        "key2": {
            "name": "ubuntu"
        }
    }
}

如何在 Firebase 中为上述对象制定这样的安全规则?

【问题讨论】:

    标签: security firebase firebase-security


    【解决方案1】:

    简单:

    {
      "rules": {
        ".read": false,
        "servers": {
          "$serverid": {
            ".read": true
          }
        }
      }
    }
    

    由于根不可读,/servers 也不可读,只有在您拥有 /servers/$serverid 后,读取操作才会生效。

    Firebase guide on Security & Rules 涵盖了这个和许多类似的主题。

    【讨论】:

    • 也许我错了,但我认为如果您取消父母的许可,那么您无法从孩子那里恢复。我会尝试看看情况如何。
    • 反之亦然:一旦您授予权限,您就无法在较低级别将其取消。
    猜你喜欢
    • 2020-06-03
    • 2013-11-22
    • 2016-07-16
    • 1970-01-01
    • 2018-09-21
    • 2021-04-09
    • 1970-01-01
    • 2018-03-17
    • 2016-06-27
    相关资源
    最近更新 更多