【问题标题】:Cloud Firestore: setting security rule based on authenticationCloud Firestore:基于身份验证设置安全规则
【发布时间】:2018-04-04 21:48:51
【问题描述】:

我想了解它是基于身份验证的安全规则有多安全,如下所示:

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

我有一个集合,其中每个文档都与特定用户相关。

我仅通过移动设备(Android 和 iOS)使用 Cloud Firestore,而不是通过网络。

有什么方法可以让用户在我的移动应用程序之外获得身份验证,从而读取或写入其他用户的文档?

【问题讨论】:

    标签: firebase-authentication firebase-security google-cloud-firestore


    【解决方案1】:

    如果你想确保用户不能读取彼此的信息,你应该实施比auth != null更强的规则。

    例如,这些规则规定,如果您的身份验证为userId,则您只能在/users/userId 读取和写入数据。

    service cloud.firestore {
      match /databases/{database}/documents {
        match /users/{userId} {
          // Anybody can write to their ouser doc
          allow read, write: if request.auth.uid == userId;
        }
      }
    }
    

    如您所述,这将使某人无法“在我的移动应用程序之外获得身份验证,从而读取或写入其他用户的文档”。

    【讨论】:

    • 上面的代码 sn-p 缺少右括号。 }
    • @SamStern 谢谢,我试过你的代码,它真的很好用,但是如何保护 android 中的 google json 文件?如果它无关紧要,那就离开吧
    猜你喜欢
    • 2019-10-17
    • 2021-07-23
    • 2021-04-08
    • 2021-07-05
    • 2019-04-04
    • 2019-06-02
    • 2019-01-20
    • 2020-07-17
    相关资源
    最近更新 更多