Firebase安全规则保护列表和公共对象

时间:2016-03-01 10:22:35

标签: security firebase firebase-security

只有拥有密钥值时,我才拥有公共访问权限的服务器列表。

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

对象示例

{
    "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中为上述对象制定此类安全规则?

1 个答案:

答案 0 :(得分:0)

简单:

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

由于root无法读取,因此/servers也无法读取,只有在您拥有/servers/$serverid后,读取操作才会生效。

Firebase guide on Security & Rules

涵盖了这个和许多类似的主题
相关问题