简体   繁体   English

Firebase规则安全警告

[英]Firebase rules security warning

I'm getting the following message in Firebase: 我在Firebase中收到以下消息:

The Cloud Firestore "(default)" database of your project contains rules that are not secure. 您项目的Cloud Firestore“(默认)”数据库包含不安全的规则。

But I have the rules as the documentation says and I don't see any other option. 但是我有文档中所述的规则,没有其他选择。 What I want is that anyone can read, but just logged in users can edit content. 我想要的是任何人都可以阅读,但只有登录用户才能编辑内容。

These are my rules: 这些是我的规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if true;
      allow read, write: if request.auth.uid != null;
    }
  }
}

With these rules any authentication user can write all documents in your database, including overwriting documents that were created by other. 使用这些规则,任何身份验证用户都可以将数据库中的所有文档写入其中,包括覆盖其他用户创建的文档。 You're also allowing everyone (no matter if they're authenticated) to read all data in the database, which seem much broader than most apps need. 您还允许所有人(无论是否经过身份验证)读取数据库中的所有数据,这似乎比大多数应用程序所需的数据要广得多。 While these are close to some of the default rules you can start with, it is typically not enough for a production app, which is why you receive the warning. 尽管这些都接近您可以开始使用的一些默认规则,但是对于生产应用程序来说,通常这还不够,这就是为什么您会收到警告的原因。

You'll typically want to further lock down access to the database. 通常,您通常希望进一步锁定对数据库的访问。 For example, you might want to ensure that users can only write documents that contain their own UID in a specific field. 例如,您可能要确保用户只能在特定字段中编写包含自己的UID的文档。 That way you'll always know who created a document, and can use that to control access to that document. 这样,您将始终知道谁创建了文档,并可以使用它来控制对该文档的访问。

If you are certain this is the minimum data access that your app requires to function, you can disable the warning emails in the Firebase console . 如果确定这是您的应用程序正常运行所需的最低数据访问权限,则可以在Firebase控制台中禁用警告电子邮件 But as said before, in my experience this type of access seems much broader than what I typically see in well functioning, and well protected, apps. 但是如前所述,根据我的经验,这种访问似乎比我在功能良好且受保护的应用程序中通常看到的访问范围要广得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM