为什么我可以使用我的网络 api 密钥发送 FCM 消息?

How come I can send FCM messages with my web api key?

我正在尝试使用 Firebase 云消息传递并尝试通过 POST 请求向我的应用程序发送通知。我使用以下 header 向 https://fcm.googleapis.com/fcm/send 发送了一个请求:

Authorization:  key=<MY-WEB-API-KEY>
Content-Type: application/json

和我的消息 body。

它有效,这就是问题所在。为什么这不是安全风险?任何进入我的网站并查看源代码的人都可以获得我的网络 API 密钥并向他们希望的任何用户发送通知。我唯一能想到的是,如果没有 FCM 令牌,他们将无法向任何人发送消息,但是他们可以向人们订阅的主题发送消息...

我还认为将此 API 密钥放入我的网络应用程序可能是我做错了什么,但它在 Firebase 控制台中说我应该这样做。

那我该怎么办?我是不是做错了什么?

编辑: 我用 Postman 发出了请求,这是它生成的请求:

POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Authorization:  key=AIza.....vI
Content-Type: application/json
cache-control: no-cache
Postman-Token: 4dd619e9-5852-4cb5-ba64-61be77478736
{
  "registration_ids":["<device-token>"],
  "notification": {
      "title":"Title of your notification",
      "body":"content of your notification"
  },
}------WebKitFormBoundary7MA4YWxkTrZu0gW--

授权 header 中的密钥是我从 https://console.firebase.google.com/project/PROJECT-NAME/settings/general/

的 Web 应用程序配置部分获得的密钥

firebaser 在这里

这原来是 Firebase 云消息服务器中的一个错误,此错误已得到修复。现在使用客户端配置片段中的 API 密钥发送 returns 401 - Unauthorized,您将需要 FCM 服务器密钥才能发送消息。

如果您以后遇到类似的安全问题,请考虑向 Google 的 Vulnerability Reward Program or through Firebase support 报告。