python - 如何使用 Stripe 保护 Django 中的 webhook

标签 python django stripe-payments payment

我有一个 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:

  1. Parse the JSON data as above.
  2. Grab the received Event object ID value.
  3. Use the Event object ID in a retrieve event API call.
  4. 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/

相关文章:

python - 在 numpy 中,如何有效地列出所有固定大小的子矩阵?

python - Python 中的 XML 和 lxml

django - Unity Web 请求 + Django : CSRF token missing or incorrect

javascript - AJAX、Django 和 HTML 选择?

stripe-payments - Stripe 在特定日期取消订阅

python - 传递给操作的参数名称是什么? (参数解析)

python - pandas dataframe.apply -- 将十六进制字符串转换为整数

python - 相对导入需要 'package' 参数

javascript - 尝试在 Controller 中使用express时出错

Go版Stripe Checkout教程无法编译,未定义: session