如何确保webhook从所需的数据源而不是第三方接收数据?

时间:2017-12-21 03:56:56

标签: node.js rest http security webhooks

我目前正在构建一个利用Shippo的webhooks功能的应用程序,但想知道是否可以确保HTTP POST请求来自Shippo的服务器而不是某些恶意的第三方。

向Shippo添加webhook: https://shippo-static.s3.amazonaws.com/img/illustrations/webhooks.png

当收到HTTP请求时,看起来好像Shippo没有提供密钥或我可以用来验证请求来自shippo的任何东西。有没有办法能够追溯并安全地确保请求来自Shippo的服务器?

示例标题:

  

User-Agent:python-requests / 2.9.1

     

Via:1.1 vegur

     

接受: /

     

连接:关闭

     

内容长度:2203

     

总路线时间:0

     

Cf-Connecting-Ip:54.87.248.176

     

Cf-Ipcountry:美国

     

X-Request-Id:cec0a1aa-6a1a-47e9-ac9d-c685a893591d

     

Cf-Ray:3d0718455e149fea-IAD

     

连接时间:1

     

Accept-Encoding:gzip

     

主持人:requestb.in

     

Shippo-Api-Version:2017-08-01

     

Cf-Visitor:{“scheme”:“https”}

     

Content-Type:application / json

示例JSON响应: https://goshippo.com/docs/tracking

1 个答案:

答案 0 :(得分:0)

你需要做两件事:

  1. 让您的webhook包含某种令牌,即有shippo call https://yourapp.com/webhookroute/?secure_token=123abc。解析并检查令牌服务器端。可以添加多个令牌,即https://yourapp.com/webhookroute/?secure_token_1=123abc&secure_token_2=456def
  2. 在部署应用程序时使用SSL / TLS证书,这将在shippo发送webhook时加密URL /令牌。确保webhook调用https:// [其余的url],而不是http://。这会将令牌隐藏在互联网的其他部分。
  3. 如果令牌设置为env vars服务器端,则应该是安全的。