我有一个 firebase 位置,其中我的应用程序存储的所有消息都作为子对象。
我希望客户端能够在知道消息 ID 的情况下获取每条消息,但不下载整个消息表。
这方面的安全规则是什么样的?
谢谢。
最佳答案
您可以禁止读取父级,但如果 ID 已知则允许读取:
"rules": {
"messages": {
// Disallow enumerating list of messages
".read": false,
".write": false,
"$messageID": {
// If you know the messageID you can read the message.
".read": true,
// Cannot overwrite existing messages (optional).
".write": "!data.exists()"
}
}
}
参见https://github.com/firebase/firepano一个使用不可猜测的 URL 来确保安全的示例应用程序。
关于firebase limit 读给单个 child ,但不读给 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17383168/