首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防火墙层次结构安全规则

防火墙层次结构安全规则
EN

Stack Overflow用户
提问于 2021-03-23 12:54:22
回答 1查看 46关注 0票数 0

我有一个限制对象的子对象访问的问题。

我需要的规则:

代码语言:javascript
复制
roles - read
-- UID
--- SUPUSR
---- settings =  read only
--- store  = write and read

我的规则

代码语言:javascript
复制
      "roles":{
     ".read":"auth != null",
     ".write":"root.child('roles/SUPUSR/').child(auth.uid).child('settings').child('pri_enabled').val() == 1 || root.child('roles/USERS/').child(auth.uid).child('settings').child('pri_enabled').val() == 1",
     "settings":{
        ".read":"auth != null",
        ".write":false
     }

如果我以上面的方式保留它,它继承了写作的“角色”规则。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-23 14:29:25

叶栅,一旦授予权限,就不能撤消它。因此,如果您允许对/roles进行写访问,任何人都可以写入/roles的任何子级,无论是自己的还是其他人的数据。

其他说明:

  • 当前的规则会影响/roles/roles/settings,这在数据库树中太高了,您应该设置/roles/SUPUSR/someUserId/roles/SUPUSR/someUserId/settings等规则。
  • auth != null的使用似乎不合适。任何登录用户应该能够读取任何其他用户的角色吗?这只适用于超级用户吗?
  • 其中一些数据对于经验证也很有意义。
代码语言:javascript
复制
{
  "rules": {
    "roles": {
      "SUPUSR": {
        "$uid": {
          // any data under /roles/SUPUSR/$uid is readable to logged in users
          ".read": "auth != null", 

          "nome": {
            // only this user can update nome, it also must be a string
            ".write": "auth.uid === $uid",
            ".validate": "newData.isString()"
          },
          "role": {
            // only this user can update role, and it must be one of a select number of string values
            ".write": "auth.uid === $uid",
            ".validate": "newData.isString() && newData.val().matches(/^(R&S|Admin|etc)$/)"
          },
          "store": {
            ".write": "root.child('roles/SUPUSR/').child(auth.uid).child('settings').child('pri_enabled').val() == 1 || root.child('roles/USERS/').child(auth.uid).child('settings').child('pri_enabled').val() == 1"
          }
          // any other keys are ".write": false, by default, which includes "settings"
        }
      }, // end /rules/roles/SUPUSR
      "USERS": {
        "$uid": {
          ...
        }
      }, // end /rules/roles/USERS
      ...
    }, // end /rules/roles
    ...
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66763551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档