我有一个 webhook View ,它接收来自支付网关的 POST
请求。它识别客户并使用提供的数据更新金额。
如果 webhook URL 以某种方式泄露,则很容易被利用。
例如
curl --data "cust_no=xxxxxxxxxx&amount=1000" https://example.com/wallet/payment_webhook/
如何确保其安全,使其不接受此类请求?它应该验证请求是否仅来自支付网关。
更新:
Webhook 请求包含交易详细信息以及客户编号。
最佳答案
它已明确记录在 webhooks documentation 上:
Best practices
[...]
For optimum security, you can confirm the event data with Stripe before acting upon it. To do so:
- Parse the JSON data as above.
- Grab the received
Event
object ID value.- Use the
Event
object ID in a retrieve event API call.- Take action using the returned
Event
object.
另请参阅Webhook-Mailer一个工作示例。特别关注this line :
# Retrieving the event from the Stripe API guarantees its authenticity
event = Stripe::Event.retrieve(data[:id])
关于python - 如何使用 Stripe 保护 Django 中的 webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35040092/