【发布时间】:2018-02-02 22:33:37
【问题描述】:
我有一个要阻止的 firebase 数据库规则:
- 未经身份验证的用户
- 试图为其他用户创建数据的用户
-
我还想阻止更新数据。为此我需要此代码:
!data.exists() || !newData.exists()
这是目前的样子:
"rules": {
"orders": {
"$order":{
".read": "auth != null && auth.token.admin === true",
".write": "auth != null && auth.uid === newData.child('userID').val()" // check the incoming data's userID value here if sender is same. or someone can send orders with other peoples ids. also anyone can send an order with id 123 but only if it doesnt exist. so they cannot update anyones order. is this safe enough?
},
".indexOn": "userID"
}
}
我应该如何包含这个“||” “.write”规则的逻辑表达式中的运算符?
我无法删除数据。是不是因为我在安全规则中检查了 newData 的子节点,而在应用程序中使用“.remove()”时没有 newData?如果是这样,在同一行中写入和删除规则如何工作?
【问题讨论】:
-
文档建议您可以同时使用 && 和 ||。你有什么具体问题?您是否正在使用身份验证模拟器来找出为什么您的规则不能按您期望的方式工作?
-
请将规则图片替换为文字。将规则作为文本使其可搜索,使我们能够轻松地使用它来测试您的实际规则并在我们的答案中使用它,总的来说这只是一件好事。
-
@DougStevenson 但我需要以某种方式在括号或其他内容中包含“!data.exists() || !newData.exists()”,并使用逻辑和添加到表达式中。如果我只是将它放在这个逻辑表达式附近,“!newData.exists()”将允许访问所有数据,因为它位于 || 之后
标签: firebase firebase-realtime-database firebase-security