Firebase/Firestore - 数据库有不安全的规则?

Firebase/Firestore - database has insecure rules?

我有一个 SwiftUI 应用程序,它使用 Firebase 作为后端,我的规则是这样的:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2020, 10, 28);
    }
  }
}

我了解这些规则允许任何人 读取和写入数据库。但是,只要他们只使用应用程序中提供给他们的API,这怎么不安全?例如,如果有人从我的笔记本电脑上拿走 xcode 项目并创建一个删除数据库中所有用户的按钮,我可以理解其中的危险。但是,没有人可以访问此代码。

我确实希望用户能够读写 to/from 数据库,所以我只是想知道这些规则是否不安全,如果是,为什么?例如,恶意黑客如何利用这些规则未经授权访问用户信息 and/or 以某种方式修改数据库,而我的应用程序中提供的 API 不允许这样做?

谢谢。

as long as they are only using the API provided to the them in the application

这正是问题所在。

您的应用包含连接到数据库(以及 Firebase 项目中的其他资源)所需的所有配置。恶意用户可以获取此配置数据,并自行调用 API - 从而绕过您的任何 client-side 逻辑。

虽然您可以 configure Firebase App Check 来帮助仅允许从您的代码访问数据库,但这并不能保证,其他人可能仍会使用 他们的 代码您的配置数据。

这就是为什么在安全规则中对业务逻辑进行编码也很重要。假设您的应用程序代码只允许用户从数据库中删除他们自己的帐户,那么您还需要在安全规则中对该逻辑进行编码,以便在服务器上强制执行。这是关于保护数据库的 Firebase 文档描述为 content-owner only access.

的变体