gpt4 book ai didi

javascript - Firebase 匿名数据安全

转载 作者:行者123 更新时间:2023-11-30 20:56:17 24 4
gpt4 key购买 nike

来自 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”。

最佳答案

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

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

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

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

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

关于javascript - Firebase 匿名数据安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47626898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com