firebase限制读取给个别孩子而不是父母

Har*_*rry 4 firebase firebase-security

我有一个firebase位置,我的所有应用程序存储的消息都是子对象.

我希望客户能够获取每条消息,如果他们知道消息的ID但不下载整个消息表.

这样的安全规则是什么样的?

谢谢.

Ana*_*ant 6

您可以禁止对父项进行读取,但如果已知该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()"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

有关使用不可访问的URL进行安全性的示例应用,请参阅https://github.com/firebase/firepano.