或者,如果您像我一样,谁还在测试模式?只需更新日期
match /{document=**} {
// from previous date 2019,12,14 to new date 2020,01,4
allow read,write: if request.time < timestamp.date(2020,4);
}
,
此处显示的安全规则与以前的默认规则相违背,后者更加宽松。使用此规则的想法:
match /{document=**} {
allow read,write: if request.time < timestamp.date(2019,14);
}
在给定日期之前,您可以不受限制地访问Firestore数据库,以便免费试用一个月。但是,从长远来看,允许不受限制的访问显然是一个巨大的安全漏洞。
建议采取的措施是首先完全删除此规则,因为它允许任何人读取和写入数据库中的任何内容。然后,设计一些适当的规则,这些规则仅允许访问最终用户应该可以访问的集合和文档。对此的完整讨论与Stack Overflow无关(因为我们不知道您应用的要求),但是这里是开始学习安全规则的一些好地方:
您应该做的是调出数据库中每个集合和子集合的访问约束。理想情况下,除非绝对需要,否则您应锁定对所有集合的未经身份验证的写访问权限。在最佳情况下,您正在使用Firebase身份验证来帮助控制对文档only as required for authenticated users的访问。
或者,如果您已经完成数据库的使用(暂时),则可以完全使用以下规则来阻止从Web和移动客户端完全访问数据库:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
allow read,write: if false;
}
}
使用此规则,仍将允许使用Firebase Admin SDK或其他Cloud 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);
}
}
}
“ timestamp.date”的日期为启动项目后的1个月。或多或少像30天免费试用。
绕过此日期后,数据库将拒绝所有客户端请求。
因此,电子邮件基本上是在提醒您更改安全规则。
一种简单的方法是只允许对经过身份验证的用户进行读/写请求。
// 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;
}
}
}
请注意,这是定义规则的一种方法,不一定完全如图所示,您可以根据需要进一步进行修改。
有关更多信息,请查看此documentation
,
Firebase] 对 Cloud Firestore 数据库的客户端访问权限将在 2 天后到期
您选择在测试模式下开始开发,这让您的 Cloud Firestore 数据库完全对互联网开放。由于您的应用容易受到攻击者的攻击,您的 Firestore 安全规则配置为在前 30 天后停止允许请求。
在 2 天内,所有客户端对您的 Firestore 数据库的请求都将被拒绝。在此之前,请编写强大的安全规则,让您的应用能够正常运行,同时适当保护您的数据。分析每天运行;如果您在过去 24 小时内修改了规则,则这些更改可能不会被考虑在内。
如果您从 firebase 收到此类电子邮件,那么您必须转到编辑规则,然后简单地更改日期。
本文链接:https://www.f2er.com/3098091.html