电子邮件:[Firebase]客户端访问您的云Firestore数据库的权限将在X天后过期

电子邮件:[Firebase]客户端访问您的云Firestore数据库的权限将在X天后过期,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我收到一封电子邮件,表明我是在“测试模式”下开发的,但它让我的数据库完全向互联网开放。我最初接受的默认规则如下所示: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { // This rule allows anyone on the internet to view, edit, and delete // all data in your Fire

我收到一封电子邮件,表明我是在“测试模式”下开发的,但它让我的数据库完全向互联网开放。我最初接受的默认规则如下所示:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2019, 12, 14);
    }
  }
}
rules_version='2';
服务云.firestore{
匹配/databases/{database}/documents{
//此规则允许internet上的任何人查看、编辑和删除
//Firestore数据库中的所有数据。这对于获取
//已启动,但已配置为在30天后过期,因为
//使您的应用对攻击者开放。此时,所有客户端
//对Firestore数据库的请求将被拒绝。
//
//确保在此之前为你的应用编写安全规则,否则
//你的应用程序将无法访问你的Firestore数据库
匹配/{document=**}{
允许读写:if request.time

需要做些什么才能满足此电子邮件的请求?

此处显示的安全规则与以前的默认规则不同,后者更为宽松。这条规则的理念是:

match /{document=**} {
  allow read, write: if request.time < timestamp.date(2019, 12, 14);
}

使用此规则,仍然允许使用Firebase Admin SDK或其他云SDK从后端代码进行访问。

每当您在Firebase上启动新项目(或)设置firestore数据库时,Firebase默认情况下会为您的数据库添加一组规则,如下所示

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(XXXX, XX, XX);
    }
  }
}
请注意,这是定义规则的方法之一,不需要完全按照所示,您可以根据需要进一步进行修改。
要了解更多信息,您可以看看这个

,或者如果您像我一样,谁仍处于测试模式?只需更新日期

match /{document=**} {  
   // from previous date 2019, 12, 14 to new date 2020, 01, 4
   allow read, write: if request.time < timestamp.date(2020, 01, 4); 
}
match/{document=**}{
//从上一日期2019年12月14日至新日期2020年1月4日
允许读写:如果request.time
Firebase]客户端访问您的云Firestore数据库的权限将在2天后过期

您选择在测试模式下开始开发,这使您的云Firestore数据库完全开放给Internet。由于您的应用易受攻击者攻击,Firestore安全规则已配置为在前30天后停止允许请求。 2天后,所有客户端对Firestore数据库的请求都将被拒绝。在此之前,请编写强大的安全规则,允许您的应用程序正常运行,同时适当保护您的数据。每天进行分析;如果您在过去24小时内修改了规则,这些更改可能不会被考虑在内


如果您从firebase收到此类电子邮件,则必须转到“编辑规则”,然后简单地更改日期。

如果仅从localhost发送,如何添加允许访问的规则?
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
match /{document=**} {  
   // from previous date 2019, 12, 14 to new date 2020, 01, 4
   allow read, write: if request.time < timestamp.date(2020, 01, 4); 
}