首页 > 解决方案 > 不受限制的 Firebase 密钥可用于其他付费 Google API

问题描述

Firebase 文档建议不应限制 firebase 自动创建的密钥,并且与其他 sercet 密钥不同,它可以愉快地出现在网站的源代码中:

与通常使用 API 密钥的方式不同,Firebase 服务的 API 密钥不用于控制对后端资源的访问;这只能通过 Firebase 安全规则来完成。通常,您需要严格保护 API 密钥(例如,通过使用保管库服务或将密钥设置为环境变量);但是,Firebase 服务的 API 密钥可以包含在代码或签入的配置文件中。

默认情况下,Firebase 自动创建的 API 密钥没有任何限制。

使用 Firebase 安全规则保护您的数据库和云存储数据,而不是限制和/或隐藏您的 API 密钥。

然而,似乎当我们在源代码中包含我们的 firebase 密钥时,恶意攻击者可以使用它来调用付费的 Google 服务,例如需要5/5000 美元查询的自定义搜索 API,从而耗尽 Google 控制台的余额可怜的毫无戒心的受害者。

此外,似乎对 Firebase 密钥添加限制不起作用 - 阻止密钥工作或触发创建新的自动生成密钥(请参见此处此处此处

那么我们应该以某种方式限制 api-key,隐藏网站源的密钥还是其他方式?

标签: firebasesecuritygoogle-cloud-platform

解决方案


I wasn't able to find anything about he malicious attacks using an API Key auto generated and can be restricted without any problem. Most of the posts you commented on have responses on how to solve their problems with the restriction options. Also, google documentation does recommend some API Key restriction.

Also, you have the App check to limit access to the backend services in your Firebase project.

Here there is also an article about security of the API keys in firebase.

So, after testing around and looking through some pages I think it's pretty safe to let some of them unrestricted and another ones restricted depending on what they are accessing to and you shouldn't have any problem.


推荐阅读