我在我的reactJS应用程序上使用了Firebase身份验证。当用户注册时,一个条目被添加到fi恢复中,以在user/(UID)存储一些帐户详细信息。
我需要制定一些规则
我尝试了以下方法:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
allow read;
allow write: if request.auth != null;
}
}
}
但是我每天都会收到一封来自Firebase的电子邮件,说我的规则不安全,任何人都可以写入我的数据库。我该如何解决这个问题?
您有一个递归通配符(/{文档=**}
),其中规则允许写入:if request. auth!=null;
允许任何经过身份验证的用户在数据库的任何集合/文档中写入。根据给定的约束,尝试将您的规则重构为:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/{sub=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}