您的Cloud Firestore数据库具有不安全的规则。什么规则最适合简单的应用程序?

时间:2020-08-13 08:32:33

标签: firebase google-cloud-firestore firebase-security

我已经收到Firebase的电子邮件,其中标明了这些帖子的标题,其中包含以下详细信息:

We've detected the following issue(s) with your security rules:
any user can read your entire database
any user can write to your entire database

我的Firebase数据库规则如下:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

我不确定该怎么办。对于我的应用程序,用户需要能够基本阅读和书写(有时需要提交内容)。有没有人提供一些技巧来更好地确保这一点,或者即使我可以做任何事情?

1 个答案:

答案 0 :(得分:2)

您是否在应用程序中使用Firebase身份验证?如果是,则将安全规则更改为此:

allow read, write: if request.auth != null;

此规则将仅允许已登录的用户获取数据并将数据写入数据库。对于一个简单的应用程序,这应该是一个很好的起点。但是,如果您不使用Firebase身份验证,则必须实施自己的身份验证方案,但是出于安全考虑,我们不建议这样做