我应该将 firebase api 键隐藏到后端吗?不是因为数据安全而是项目克隆问题

Should I hide firebase api keys into backend? Not due to data security but project cloning issue

有人可以帮我解决 Firebase 安全问题吗?
这是我试图弄清楚的:

我知道为了让客户端与我的 firebase 应用程序交互,配置和 firebase.initializeApp(config) 将暴露给 public,每个使用客户端的人都可以在浏览器开发者控制台中看到它.

我也知道这很好,因为我可以使用安全规则和身份验证来保护数据。

但是,如果有人复制了我的所有客户端代码(包括配置)并构建了大量克隆站点,那么他们可以随心所欲地使用我的 firebase 数据库,对吗?

在这种情况下,我是否应该将配置(api 键)隐藏到后端,如云函数之类的? 谢谢...

我以前也想过类似的问题,经过一番搜索后找到了 this handy article。 (文章本身是关于移动开发的,但有一个部分解决了这个特定问题)。相关部分的标题为“API 域和程序包阻塞

这篇文章比我解释得更好,以防万一 link 出现故障,我将复制下面的文字以供将来的浏览者参考。这是 Jorge Vergara 在他的网站上写的 https://javebratt.com/hide-firebase-api/ 最后更新于 2018 年 7 月 20 日。

Another cool thing, if you go to your Google APIs account, you’ll see all of your Firebase projects, pick one, and in the Credentials Tab select your API key.

If you’ve never messed with it, it should be called something like Browser key (auto created by Google Service), open it, and you’ll find options for key restriction:

This key is unrestricted. To prevent unauthorized use and quota theft, restrict your key. Key restriction lets you specify which websites, IP addresses, or apps can use this key.

There you can choose HTTP referrers (websites) and add your domain. This means that the Firebase database will only accept requests for people writing from that domain.

Or Android apps and iOS apps, where you can add package name and fingerprints.

For example:

If you build myawesomeapp.com and add the domain in the HTTP referrers (websites) section, any attacker trying to connect from a different domain will get an error, and those requests will never make it to the database.

他提供的用于访问您的 Google API 帐户的 link 是:https://console.developers.google.com/apis/credentials

如果您单击显示“浏览器密钥(由 Google 服务自动创建)”的 link,那么您应该会看到“Application Restrictions" 部分朝向底部,您可以在其中 select "HTTP Referrers"... 单击它可以输入已批准的域.

无需尝试隐藏您的 API 密钥。它本质上是 public 信息,无论您如何努力混淆它,坚定的黑客都能够掌握它。

黑客并不能通过获取您的 API 密钥真正获利。它只是您项目的唯一标识符。如果您想保护实时数据库和云存储中的数据,您应该结合使用安全规则和 Firebase 身份验证来保护仅应具有该访问权限的用户的访问权限。