Firebase 实时数据库安全规则(读取和写入)

发布于 2025-01-19 22:55:10 字数 272 浏览 4 评论 0原文

好的,我有一个连接到应用程序的实时数据库,直到今天,规则(读写)都设置为True,一切正常。...但是每次弹出消息时,

您的安全规则定义为公共,因此任何人都可以在数据库中窃取,修改或删除数据

我尝试了几件事,但没有访问数据...只有在将规则设置为true

时才可以访问数据修改规则以使其更安全的任何方法

我希望仅通过少数已知的应用程序(我的应用程序)访问这些数据

Ok I have a Realtime database connected to a app and till today the rules ( read and write ) were set to true , everything was working fine ....but every time a message pops up saying

Your security rules are defined as public, so anyone can steal, modify, or delete data in your database

I tried few things but data was not accessed...data was only accessible when the rules were set to true

but is there any way to modify the rules to make it more secure

I want this Data to be accessed by only few known apps ( My Apps )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彩虹直至黑白 2025-01-26 22:55:10

文档中的此处开始,然后逐步完成。它非常实用且易于理解。

仅当规则设置为 true 时才能访问数据

Firebase RTDB 具有公共 URL,因此任何人都可以尝试连接到它。您的工作是决定他们是否可以这样做。如果您的任何路径/节点的规则如下所示,则任何发出请求的人都可以使用它:

{
  ".read": true,
  ".write": true
}

如果您只想允许应用程序的用户连接到 RTDB,则可以使用 Firebase Auth 并使用如下条件:

{
  ".read": "auth != null"
  ".write": "auth != null"
}

我希望仅少数已知应用程序(我的应用程序)可以访问此数据

访问权限是在用户级别而不是应用程序上确定的。从文档中的此处开始。

但是有没有办法修改规则以使其更安全

在 Firebase 控制台中或通过 CLI 部署它们。如果您对此不熟悉,请从 Firebase 控制台开始,然后使用规则园地来测试不同的规则。 有关详细信息,请参阅文档

因此,除非有人可以访问我的 Google 帐户或与我的数据库集成的应用程序/网络...即使规则设置为 true,也没有人可以访问数据,对吗?

您的数据库不是“集成的”。它是一个可通过公共 URL 访问的已部署实例 - 这就是您的客户端连接到 RTDB 的方式。如果您的规则允许任何读取或写入操作,那么您的数据库就是广泛的并且对每个人开放。因此,您收到的电子邮件通知您这不安全。

Start here in the docs and work your way through. It's very practical and easy to understand.

data was only accessible when the rules were set to true

Firebase RTDB has a public URL, so anyone can try connecting to it. It is your job to decide whether they can do this or not. If your rules for any path/node look like this, it is available to anyone who makes a request:

{
  ".read": true,
  ".write": true
}

If you only want to allow users of your app to connect to RTDB, you can use Firebase Auth and use conditions like this:

{
  ".read": "auth != null"
  ".write": "auth != null"
}

I want this Data to be accessed by only few known apps ( My Apps )

Access is determined on a user level, not by app. Start here in the docs.

but is there any way to modify the rules to make it more secure

Either in the Firebase Console, or deploy them via the CLI. If you're new to this, start with the Firebase Console and use the Rules Playground to test different rules. See docs for more information.

So unless someone has access to my Google account or a app /web integrated with my database... No one can access the data even if the rules are set to true, am I right ?

Your database is not "integrated". It is a deployed instance that is reachable via a public URL - that's how your clients connect to RTDB. If your rules allow any read or write operation, then your database is wide and open for everyone. Hence, the email that you have received informing you that this is not secure.

混浊又暗下来 2025-01-26 22:55:10
{
  "rules": {
   ".read": "auth.uid !== null",
   ".write": "auth.uid !== null"
  }
}

当前接受的规则

{
  "rules": {
   ".read": "auth.uid !== null",
   ".write": "auth.uid !== null"
  }
}

Currently accepted Rule docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文