【问题标题】:To what extent are the firebase rules of Childs overridden by rules set for 'parents' in the database?Childs 的 firebase 规则在多大程度上被数据库中为“父母”设置的规则覆盖?
【发布时间】:2020-07-27 09:17:06
【问题描述】:

说数据库中的 topline 你允许授权用户阅读但是这个数据库条目的 Childs 你只允许授权用户阅读他们自己的条目。让所有 auth 用户读取 topline 的能力会使 auth 用户只能读取自己的子规则无效吗?

具体来说,人和 uid 会使坐标无效吗?

{
  "rules": {
  "people" : {
    ".read": "auth.uid != null",
    ".write": true
   ,"$uid": {
      ".read": "auth.uid != null",
      ".write": "$uid === auth.uid"
     ,  "Education" :{
         ".read": "auth.uid != null",
        ".write": "$uid === auth.uid"
      }
      ,"Coordinates" : {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }  
       ,"ForReUpload": {
        ".read": "auth.uid != null",
       ".write": "$uid === auth.uid"
  }
      ,"PhotoPosts": {
      ".read": "auth.uid != null",
     ".write": "$uid === auth.uid"
      }

      ,"WhatIamConsideringBuying":  { 
      ".read": "auth.uid != null",
      ".write": "$uid === auth.uid"
  }
      ,"caption": {
        ".read": "auth.uid != null",
    ".write": "$uid === auth.uid"
  }
      ,"peopleWhoLike" : {
        ".read": "auth.uid != null",
        ".write": "$uid === auth.uid"
  }
      ,"peopleWhoLike2" : {
     ".read": "auth.uid != null",
    ".write": "$uid === auth.uid"
  }

      ,"postID" : { 
     ".read": "auth.uid != null",
    ".write": "$uid === auth.uid"
  }
      ,"users" : {     
     ".read": "auth.uid != null",
   ".write": "$uid === auth.uid"  
  }
    }
  }
  }
}

【问题讨论】:

    标签: firebase-realtime-database firebase-authentication firebase-security


    【解决方案1】:

    是的,任何适用于高级别的规则都会影响其下的所有子级。子级无法删除更高级别授予的访问权限。我建议阅读讨论read and write rules cascade:

    较浅的安全规则会覆盖较深路径的规则。子规则只能授予父节点已经声明的额外权限。他们不能撤销读取或写入权限。

    .read 和 .write 规则自上而下工作,较浅的规则覆盖较深的规则。如果规则授予特定路径的读取或写入权限,则它还授予对其下所有子节点的访问权限。

    【讨论】:

    • 谢谢。有没有办法不给 topline 数据库条目任何规则,而只处理端点子项?归根结底,那些应该在级别或安全性上有所不同的那些,以及那些重要的。我的问题只是坐标。我不希望它们可读(即容易受到 api 攻击),但是我想再次使用各种用户坐标来计算 then 之间的距离(已经这样做了)。是否有可能让其他用户无法读取坐标并对应用程序进行编码,以便计算用户之间的距离并用于对他们进行排名?
    • 您可以在顶层拒绝访问,然后在更深的级别允许它。
    • @Doug Stevenson 谢谢。这就说得通了。我唯一担心的是甚至允许对坐标进行较低的读取访问,这是否仍然会使它们容易受到 api 攻击?我在应用中使用 CLLocationCoordinate2D 来计算用户之间的距离。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多