是否可以编写一个Firestore安全角色来防止恶意用户通过更新清除文档中的所有数据?
我已经制定了防止文档删除的规则,但是我担心用户仍然可以使用Firestore安全性的“更新”部分来更新文档并使用Firestore的“ setData”方法清除所有数据。
match /stories/{document=**} {
allow read, create, update: if request.auth.uid != null;
allow delete: if request.auth.uid == resource.data.creatorID;
}
以上是我的示例规则。如果文档为空,可以使用
阻止更新resource.data != null || resource.data != ""
还是类似的东西?有人这样做吗?
答案 0 :(得分:0)
对于任何想知道的人,要解决此问题,我将需要某些键。例如,我只允许用户更新自己的数据(request.auth.id == resource.id)或更新某些字段(喜欢,关注者人数等)。
match /users-metadata/{document=**} {
allow read: if true;
allow create: if request.auth.uid != null;
allow update: if request.auth.uid == resource.id
|| request.resource.data.keys().hasAny(['userInvites','submission-likes','following-count', 'follower-count']);
}