【问题标题】:How do I secure my firestore for anonymous access of product data如何保护我的 Firestore 以匿名访问产品数据
【发布时间】:2020-11-30 06:03:42
【问题描述】:

我正在为我的网站使用 FireBase / Firestore - 我在网站上显示了存储在数据库中的产品。 - 目前,我的规则设置为

 match /{document=**} {
      allow read: if true
      allow write,create,update, delete: if request.auth.uid !=null
}

我现在收到来自 Firebase 的邮件,警告我有关我的不安全规则:

[Firebase] Your Cloud Firestore database has insecure rules

    We've detected the following issue(s) with your security rules:
any user can read your entire database
Because your project does not have strong security rules, anyone can access your entire database. Attackers can read all of your data, and they can drive up your bill.

我如何正确保护我的数据库,但允许我的网站在不要求访问者登录的情况下读取产品数据?

【问题讨论】:

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


    【解决方案1】:

    这封电子邮件警告您,由于match /{document=**},任何人都可以阅读您整个数据库中的任何文档。您应该完全避免使用此全局通配符,因为它可能会导致意外的安全问题。相反,您应该调用具有对该集合的特定访问权限的每个单独的集合。至少,它看起来更像这样:

    match /collection1/{document=**} {
        allow read: if true
        allow write,create,update, delete: if request.auth.uid !=null
    }
    
    match /collection2/{document=**} {
        allow read: if true
        allow write,create,update, delete: if request.auth.uid !=null
    }
    

    这种形式是否适合您的应用尚不清楚。您的规则需要对您的应用的特定权限进行编码。每个应用程序都会有所不同,您的规则需要根据您的安全要求进行定制。您正在有效地将应用程序逻辑写入规则中,因此请像对待任何其他代码一样对待它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2021-10-17
      • 2015-11-26
      • 2013-02-05
      • 2019-01-01
      相关资源
      最近更新 更多