Firebase 匿名数据安全
Firebase Anonymous Data Security
来自 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 规则过滤数据,如 Firebase 文档 this section 中所述。我建议您更新模式并为您的匿名包提供一个单独的节点,例如:
{
"rules": {
".read": "auth != null && auth.provider == 'password'",
"anonymousBundles": {
".read": "auth != null"
}
}
}
来自 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 规则过滤数据,如 Firebase 文档 this section 中所述。我建议您更新模式并为您的匿名包提供一个单独的节点,例如:
{
"rules": {
".read": "auth != null && auth.provider == 'password'",
"anonymousBundles": {
".read": "auth != null"
}
}
}