firebase - Firebase Flutter:Cloud Firestore 数据库的规则不安全
问题描述
Firebase 不断告诉我
我们检测到您的安全规则存在以下问题:任何用户都可以读取您的整个数据库
我已经更改了规则,但该规则在我的应用程序中不起作用,因为所有用户都可以从 db 读取,并且只有经过身份验证的用户才能写入 db。
Firebase 说应该在我们登录之前执行写入和读取。但在我的情况下,每个用户都可以读取,只有登录用户可以写入。
任何想法如何解决这个问题?还是我做错了?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read;
allow write: if request.auth != null;
}
}
}
解决方案
您可以将 read 明确设置为 false 吗?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if false;
allow write: if request.auth != null;
}
}
}
那应该这样做。让我知道它是否持续存在。根本原因是,即使您只允许经过身份验证的用户读取或写入,但他们可以访问整个数据库,如Google Cloud Firestore 文档中所述。这也意味着任何经过身份验证的用户都可以在您的数据库中写入任何内容。
如果您的数据库对每个用户都有单独的文档,我建议使用以下规则,允许用户仅写入/读取自己的数据。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth.uid === userId;
}
}
}
推荐阅读
- testing - TestCafe 屏幕截图:Android 浏览器提供程序。crop.js "在浏览器窗口截图中找不到页面区域"
- python - 不能使用参数化构造函数进行多重继承
- sql - Datediff 不包括周末
- laravel - 如何将 laravel 会话传递给 vue.js
- java - 使用 jpa 2.x 调用存储过程会引发非法ArgumentException
- r - 从具有多个 ifelse 条件的不同长度数据集中聚合列
- react-native - 如何在 React Native 中更改地图坐标格式?
- javascript - 选中复选框的 Framework7 数据表
- ios - 添加 Firebase In-AppMessaging 和 CloudMessaging 后 Appstore 上传被拒绝
- oracle - Oracle 数据库中的 JDBC 删除表、视图、函数过程