【问题标题】:Is FCM on the web secure without an app server?如果没有应用服务器,FCM on web 是否安全?
【发布时间】:2017-01-11 20:17:38
【问题描述】:

我想从我的站点上的客户端生成消息,并将消息发送到目标设备。像这样的 ajax(jquery) 请求很简单:

$.ajax({
    url: 'https://fcm.googleapis.com/fcm/send',
    type: 'POST',
    contentType: "application/json",
    dataType: 'json',
    data: JSON.stringify({
        "notification": {
            "title": title,
            "body": msg,
            "sound": "default"
        },
        "to": "XXXXXXXXXXXX"
    }),
    beforeSend: function(xhr) {
        xhr.setRequestHeader('Authorization', 'key=YYYYYYYYYY');
    }
});

但是,我不需要将 XXXXXXXXXXXX 设备密钥和 YYYYYYYYYY API 密钥保密吗?如果没有,我担心人们会开始从完全不相关的服务中抓取这些内容并发送垃圾邮件?

【问题讨论】:

  • 我意识到我可以向应用服务器发送请求以发送此消息并将密钥保密,但我认为 firebase 的一个主要功能是它可以防止需要使用您自己的后端。一般来说,我不知道你怎么能两者兼得。
  • 万一有人发现了这个,现在有答案了! firebase.google.com/docs/functions

标签: firebase firebase-cloud-messaging


【解决方案1】:

这绝对不安全。您传递给 Authorization 标头的密钥称为 server 密钥,因为您只应该在应用服务器上使用它(或在您直接控制的其他进程中) .

如果您将相同的密钥放入每个客户端设备上运行的代码中,则意味着恶意用户可以(因此将)复制您的服务器密钥并使用该密钥代表您向您的应用用户发送消息。

Firebase 云消息传递文档在其section on FCM Server roles 中对此进行了说明。我们还有一个blog post that explains how to send device-to-device messages on Android using Cloud Messaging, the Realtime Database and a Node.js script on your back-end, app server

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-05
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    相关资源
    最近更新 更多