fix: Mercado Pago's signed notifications verify with a pasted secret and close formats
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 2m43s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 54s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 2m43s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 54s
Production refused every notification, all current-format (data.id, type), signed and fresh, though the event and the secret looked right. The secret is now trimmed (a space or line break pasted into the stack changes every HMAC), and a few close variants of the signed text are tried besides the documented one (without the request id, the id's own case, the id from the body); each still needs the secret. The one that matched, and whether the secret was trimmed, go to the audit log so the real format can be settled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,10 @@ async def webhook(request: Request):
|
||||
age=signature_age(request.headers.get('x-signature', '')))
|
||||
raise HTTPException(403, 'Invalid signature')
|
||||
|
||||
if getattr(payment, 'last_signature', 'documentado') not in (None, 'documentado') or getattr(payment, 'secret_was_trimmed', False):
|
||||
# Genuine, but not quite as documented: say how, so it can be settled.
|
||||
audit('payment_webhook_signature', variant=payment.last_signature,
|
||||
secret_trimmed=getattr(payment, 'secret_was_trimmed', False))
|
||||
event = payment.parse(body, query)
|
||||
if event is None:
|
||||
# Verified, so genuinely from the provider, but not about a payment.
|
||||
|
||||
Reference in New Issue
Block a user