fix(rails-security): take the webhook replay key from the signed payload

- The HMAC covers the request body, not the headers, so deduplicating on
  X-Delivery-Id let a replay vary that header and queue the work again
- Uses the event id parsed from the signed body as the dedupe key
This commit is contained in:
Rockwell Windsor Rice committed 2026-11-08 09:15:30 -06:00
1 parent 4b8da913be
commit 36dedf4646
1 file changed
+2 -6
+2 -6
View File
@@ -356,12 +356,8 @@ class WebhooksController < ApplicationController
return head :unauthorized
end
# A valid signature proves authenticity, not freshness. Dedupe on the
# provider's delivery id so a replayed delivery does not repeat the work.
delivery = WebhookDelivery.create_or_find_by!(
provider: "billing",
delivery_id: request.headers.fetch("X-Delivery-Id")
)
event_id = JSON.parse(request.raw_post).fetch("id")
delivery = WebhookDelivery.create_or_find_by!(provider: "billing", delivery_id: event_id)
return head :ok if delivery.processed_at?
ProcessWebhookJob.perform_later(delivery.id, request.raw_post)