Firebase-您的Cloud Firestore数据库具有不安全的规则,该如何解决?

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

[我使用firebase rest API来访问我的firebase数据库,但是我收到来自firebase的电子邮件,其中指出“ [Firebase]您的Cloud Firestore数据库具有不安全的规则”。我试图在数据库中添加一些规则,如下所示

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

但是添加了规则之后,我无法再使用REST API查询数据库,它会在下面返回

{
  "error": {
    "code": 403,
    "message": "Missing or insufficient permissions.",
    "status": "PERMISSION_DENIED"
  }
}

任何人都知道如何编辑规则以确保数据库安全,同时仍然可以通过REST API访问。

谢谢

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

不是直接来自Web或移动客户端的访问Cloud Firestore,或者不使用Firebase身份验证令牌的访问,完全不受安全规则的影响。如果仅使用后端SDK或服务帐户来访问数据库,则只需将安全规则设置为拒绝所有访问即可:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.