Firebase功能是否遵循Firestore安全规则?

时间:2020-05-13 05:20:40

标签: firebase google-cloud-firestore google-cloud-functions

我的firestore安全规则如下:

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

当我在Firestore中进行仿真时,一切看起来都很好。

我具有firebase功能来放置/获取数据

await document.set({
    name: jbose12,
      });
      console.log('Entered new data into the document');
}

即使我提供了错误的uid,它也会在firebase中创建/推送数据。

1 个答案:

答案 0 :(得分:0)

安全规则仅适用于使用Firebase客户端SDK直接来自Web和移动客户端的访问。它们不适用于后端代码,包括使用Firebase Admin SDK或其他Cloud SDK在Cloud Functions中运行的代码。后端代码将始终绕过所有规则。

如果您要遵守后端的按用户访问规则,则必须在该函数中编写代码以进行检查。对于HTTP类型的函数,您需要使您的客户端应用程序向该函数传递ID令牌,并在执行写入之前使用Firebase Admin SDKverify the ID token