Ingenious AI

Guides · Payments and fraud

Webhook and callback security guide

Webhooks are how modern systems tell yours that something happened — a payment cleared, a shipment moved, a user verified. Your system then acts on that news: releasing goods, granting access, marking invoices paid. Which means a forged webhook is a forged reality, and attackers know it. This guide covers the verification discipline that makes callbacks trustworthy: signatures, freshness, idempotency, and the quiet failure modes in between.

By the Ingenious AI team · Published 14 November 2026 · Reviewed 14 November 2026

The short answer

Secure webhooks by verifying the provider's signature on every callback (using the raw body, with a constant-time comparison), rejecting stale timestamps to stop replays, processing each event idempotently so a repeated delivery cannot double-apply, and responding fast while doing heavy work asynchronously. Never act on an unverified callback, never trust a success status you have not confirmed against the provider's API for high-value events, and log every callback with its verification result — a fake-callback attempt in your logs is an attack in progress.

Try it free: CallbackShield — protect the payment callbacks your systems act on — verified signatures and replay defence, built for the job.

What is webhook security?

the practice of authenticating and safely processing inbound HTTP callbacks (webhooks) that external systems send to yours to report events. Because a webhook is just an HTTP request anyone on the internet can send to a public URL, its trustworthiness comes entirely from cryptographic verification and careful processing — not from the URL being obscure, which it never stays.

Signatures: verify every time, on the raw body

Reputable providers sign each webhook with a shared secret (HMAC) or a public-key scheme. Verification must use the exact raw request body — parsing and re-serialising JSON first invalidates signatures and tempts developers to disable checks 'temporarily'. Compare signatures in constant time to avoid timing leaks, keep the signing secret in your secrets manager (rotated when staff leave or on suspicion), and support the provider's dual-secret rotation windows rather than hard-failing during their key changes. A callback handler without signature verification is not an integration; it is a public 'mark anything paid' button.

Freshness and replay: old news must not act twice

A captured genuine callback is still dangerous: replayed, it can re-trigger fulfilment or confuse reconciliation. Check the signature's timestamp and reject events outside a short window (five minutes is a common tolerance). Combine that with idempotency: record each event's unique ID and make processing safely repeatable, so the provider's legitimate retries (which are normal — networks fail) apply exactly once. Refunds, fulfilment and access grants should all be designed so that 'the same event again' is a no-op, not a second payout.

Confirm high-value events against the source

For events that move money or grant valuable access, treat the webhook as a hint, not as truth: fetch the object's current state from the provider's API with your credentials and act on that. This defence-in-depth step neuters whole classes of attacks and bugs (misconfigured secrets, test-mode events reaching production handlers, partially spoofed payloads). It costs one API call per important event — cheap insurance measured against a single fraudulent fulfilment.

Endpoint hygiene: the handler as a public surface

Your callback URL is a public endpoint and should be engineered like one: HTTPS only, rate limits, a framework that does not leak stack traces, and no other functionality sharing the route. Separate handlers per provider, each with its own secret, so one provider's incident does not contaminate the rest. Keep test and production endpoints and secrets strictly apart — a remarkable share of callback fraud is really a test-mode event honoured by a production system, or a handler that accepts both environments' secrets.

Logging and alerting: attempts are intelligence

Log every callback with provider, event ID, verification result and processing outcome. Alert on verification failures in bursts — someone is probing your handler — and on events for objects you do not recognise. Review the logs in incident response as a first-class source: payment disputes and 'we fulfilled but they never paid' cases are usually solved in the callback log in minutes, if the log kept the verification result and the raw payload. Retain callback logs at least as long as your payment-dispute horizon.

Your 5-action checklist

  1. Verify every callback signature on the raw body with constant-time comparison; secrets in a manager, rotated on suspicion.
  2. Reject stale timestamps (short window) and make all processing idempotent on the provider's event ID.
  3. For money-moving events, confirm state via the provider's API before fulfilling.
  4. Keep handlers HTTPS-only, rate-limited, per-provider, with test and production strictly separated.
  5. Log verification results and payloads; alert on failure bursts and unknown-object events.

Worked example: San Ignacio Tour Payments

San Ignacio Tour Payments, a fictional booking platform for local operators, fulfilled tours on payment-provider webhooks. A quarterly review — prompted by a chargeback puzzle — found its handler verified signatures, but its predecessor code had also left a legacy endpoint live that accepted unsigned 'payment confirmations' from an older integration. No fraud had used it yet; the reviewer's test call marked a $0 test booking as paid in seconds, proving the door was open. The legacy route was deleted, all endpoints were inventoried (three more forgotten test handlers were removed), and high-value bookings gained the API-confirmation step. The platform's founder summarised the lesson for the team: a webhook handler is a cashier who believes what it is told — so the engineering job is to make sure it only believes signed, fresh, confirmed news.

Sources

Frequently asked questions

Our provider does not sign webhooks. What then?

Use every compensating control: confirm each event via the provider's authenticated API before acting, restrict by source IP if the provider publishes ranges (weak, but layered), and put high-value actions behind human review. Then press the provider on signing — in 2026, unsigned webhooks are below the professional standard for payment events.

Why does signature verification fail on our real events?

The usual causes: verifying a re-serialised body instead of the raw bytes, the wrong secret (test vs production), or a proxy that altered the payload. Debug with the provider's test tooling and a captured raw request. Never respond to flaky verification by disabling it — that converts a bug into a vulnerability.

How do we handle webhook retries safely?

Acknowledge fast (200) after durably recording the event, then process asynchronously. Idempotency keys (the provider's event ID) make retries harmless. A handler that does slow work inline times out, invites retries, and then processes duplicates — the classic double-fulfilment recipe.

Should webhook endpoints require authentication as well as signatures?

The signature is the authentication. Additional layers (IP allowlists where ranges are stable, mutual TLS where offered) add depth but must not substitute for signature checks — IPs change and get spoofed at the edges, while a correct HMAC is bound to the payload itself.

What do we log without creating a privacy problem?

Log the event metadata, verification outcome and the payload needed for dispute handling, under the same retention and access rules as your payment records. Payloads can contain personal data; treat the callback log as a financial record — restricted, retained deliberately, and never shipped to a general analytics tool.

Related guides and tools