4

所以我有这个应用程序,允许匿名用户写入但不能读取特定路径。他们正在将数据发布到一个有节制的留言板之类的东西上。

但是根据我当前的安全规则,它们也可以覆盖现有数据。如何禁止更新并只允许新帖子。

我目前的安全规则:

{
  "rules": {
     ".read": "auth != null",
     ".write": "auth != null",
    "inbox" : {
     ".write": true,
    },
    "moderated" : {
      ".read": true,
    },
  }
}
4

1 回答 1

6

用于data.exists()确定他们尝试写入的对象是否已经存在:

{
  "rules": {
     ".read": "auth != null",
     ".write": "auth != null",
     "inbox" : {
       "$post" : {
          ".write": "!data.exists()",
       }
     },
     "moderated" : {
       ".read": true,
     },
  }
}
于 2013-09-18T18:16:20.417 回答