【问题标题】:Firebase Anonymous Data SecurityFirebase 匿名数据安全
【发布时间】:2018-05-17 12:53:08
【问题描述】:

来自 JS 应用的 Firebase 实时数据库安全性。

我允许所有密码验证用户具有读取权限。 然后,对于所有其他类型(根据我的方案,仅匿名),我想只允许读取特定的 /bundles/。

这些是规则-

{
    "rules": {
        ".read": "auth != null && auth.provider == 'password'", // working!
        "bundles": {
            "$bundle": {
                ".read": "data.child('anonymous').val() == true", // not working
            }
        },
    }
}

还有 /bundles -

  "-L-2BbIkAg6J9WPMaJpJ": {
    "anonymous": true,
    "more_data": "data_1"
  },
  "-L-UHBr45eEUHGwsPWqq": {
    "anonymous": false,
    "more_data": "data_2"
  }

我希望在以匿名身份登录时只看到第一个捆绑包,但我从 FB 收到错误 - “permission_denied at /bundles”。

【问题讨论】:

  • AFAIK Firebase 规则不过滤数据。您是否尝试进行类似ref.child('bundles').once('value') 的查询?
  • 它可以被视为过滤,但我的想法来自 - firebase.google.com/docs/database/security/…。具体来说 - "rules": { "messages": { "$message": { // 只能读取最近十分钟的消息 ".read": "data.child('timestamp').val() > (现在 - 600000)", } } }

标签: javascript firebase firebase-security


【解决方案1】:

.read 失败,因为您尝试访问 /bundles 位置。相反,如果您直接查询特定的捆绑包,它将通过:

// read denied
ref.child('bundles').once('value')

// read allowed
ref.child(`bundles/-L-2BbIkAg6J9WPMaJpJ`).once('value')

您将无法通过 Firebase 规则过滤数据,如 Firebase 文档的 this section 所述。我建议您更新架构并为您的匿名包提供一个单独的节点,例如:

{
  "rules": {
    ".read": "auth != null && auth.provider == 'password'",
    "anonymousBundles": {
      ".read": "auth != null" 
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2018-05-02
    相关资源
    最近更新 更多