firebase - 没有身份验证的 Firestore 安全规则
问题描述
我使用 Firestore 和 firebase 存储存储了我的投资组合应用程序数据。我的应用程序中没有用户输入或注册,这是一个简单的作品集来展示我的作品。我希望任何用户都能够读取来自我的 firestore 和 firebase 存储的数据。
我目前的规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true;
}
}
}
我对这个规则的问题是攻击者可以用请求来流动我的应用程序。我什至收到警告邮件说“因为你的项目没有强大的安全规则,任何人都可以访问你的整个数据库。攻击者可以读取你的所有数据,他们可以提高你的账单。”
我没有存储任何敏感数据,但我想防止谷歌收取额外费用。如何设置我的 Firestore 安全规则以使任何用户无需身份验证即可阅读但防止攻击?
解决方案
Firebase 安全规则不喜欢数据库点保持打开状态,而这通常通过安全规则和身份验证来完成,您可以根据文档内部的值定义文档的可读性。
在此示例中,文档的布尔值为Public
service cloud.firestore {
match /databases/{database}/documents {
// Allow the user to read data if the document has the 'visibility'
// field set to 'public'
match /{document=**} {
allow read: if resource.data.public == true;
}
}
}
推荐阅读
- android - 仅当 android 中的 api 调用完成时才返回布尔函数
- python - 拆分和连接字符串中的单词以删除单词之间的多余空格
- python - 从 TWILIO 的 HTTP GET REST API 响应中使用分页消息的最佳 Python 设计模式是什么?
- unit-testing - 如何防止记录在odoo单元测试中提交
- c# - 无法在 program.main Blazor 客户端 wasm 中命中断点
- python - 如何使用形状为 (N,) 的一维数组索引维度为 N 的 numpy 数组
- c# - 如何允许 C# Razor 页面 SelectList 的空输入
- first-order-logic - 证明¬P → ( P → ( P → Q)) 是一个重言式而不使用真值表
- c++ - 函数参数说明
- database - Qlik Sense - 创建一个列表或图表,在单击项目时将加载表格(QVD 对象)