通过 Cloud Functions 访问时如何配置 Firestore 规则

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

我(现在)知道 Firestore 收集规则仅在通过浏览器/应用程序访问时适用。 通过云功能访问 Firestore 时不会使用它们。

虽然不理想,但我可以在云功能中编写自己的支票。

但是,如何确保 Firestore DB 在浏览器上的安全?

如果我设置这样的规则,从云功能内向 Firestore 发出的任何请求都会失败 - 我认为是因为 request.auth 为 null。

rules_version = '2';

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

如何在不破坏云功能访问的情况下保护浏览器访问?

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

如果我设置这样的规则,则从 Cloud Function 内向 Firestore 发出的任何请求都会失败

使用 Cloud Functions 执行的所有访问 Cloud Firestore 的操作都将完全绕过安全规则。安全规则仅适用于网络和移动客户端。

我认为是因为 request.auth 为空。

仅当在客户端上执行读取或写入操作且用户未经过身份验证时,这些规则才会拒绝这些操作。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.