电子邮件:[Firebase]对您的Cloud Firestore数据库的客户端访问权限将在X天内到期

问题描述 投票:0回答:1

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

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);
    }
  }
}

满足此电子邮件的要求需要做什么?

firebase google-cloud-firestore firebase-security-rules
1个回答
0
投票

此处显示的安全规则与以前的默认规则相违背,后者更加宽松。这个规则的想法:

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

是指您可以在给定日期之前不受限制地访问我们的Firestore数据库,以便免费试用一个月。但是,从长远来看,允许无限制访问显然是一个巨大的安全漏洞。

建议的操作方法是首先完全删除此规则,因为它允许任何人读写数据库中的任何内容。然后,设计一些适当的规则,这些规则仅允许访问最终用户应该可以访问的集合和文档。关于堆栈溢出的完整讨论是离题的(因为我们不知道您的应用程序的要求),但是这里是一些开始学习安全规则的好地方:

您应该做的是调出数据库中每个集合和子集合的访问限制。理想情况下,除非绝对需要,否则您应锁定对所有集合的未经身份验证的写访问权限。在最佳情况下,您正在使用Firebase身份验证来帮助控制访问权限,仅根据经过身份验证的用户的要求。

© www.soinside.com 2019 - 2024. All rights reserved.