繁体   English   中英

如何阻止 firestore web 客户端根据文档内容阅读规则中的某些文档?

[英]How do I stop a firestore web client from reading certain documents in rules based off a documents content?

出于某种原因,我可以运行规则模拟器并且它运行良好(拒绝读取已将专用设置为 false 的文档)但是如果我从以下位置删除“Where”语句,js 应用程序仍会提取所有文档:


    firebase.firestore().collection('live').where('dedicated', '==', false).onSnapshot
to
    firebase.firestore().collection('live').onSnapshot

我需要能够列出文档,但不能阅读带有 dedicated = true 的文档。 我知道规则不是过滤器,但我计划保留 where 语句并且仍然希望限制对某些文档的访问以确保安全。

规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /live/{document} {
      allow list: if true;
      allow read: if resource.data.dedicated == false;
    }
...

因为你的规则说:

allow list: if true;

这意味着您允许 API 调用无条件地检索文档列表。

如果你只想允许第一个查询,你应该使用:

allow list: if resource.data.dedicated == false;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM