Skip to content

Webhook Security: HMAC Signatures & Replay

Secure inbound and outbound webhooks: verify HMAC-SHA256 signatures in constant time, block replay attacks with timestamps, and prevent outbound SSRF.

By BugSnaps Security Research · 2 min read · Updated

Add BugSnaps as a preferred source on Google(opens in a new tab)

Want more of our security guides? Select BugSnaps and confirm your choice on Google.

Webhooks connect modern SaaS applications to payment gateways, identity providers, source-control platforms, and customer integrations. Because an inbound webhook endpoint is a publicly reachable HTTP POST route—and an outbound webhook feature lets users tell your server where to send HTTP requests—both directions require explicit security controls.

Securing inbound webhooks against forgery and replay

An inbound webhook route (such as `/api/webhooks/billing`) cannot rely on a browser session cookie because the request comes from an external provider's server. Without cryptographic verification, anyone who discovers the endpoint URL can POST a forged JSON payload:

  • Verify HMAC signatures over the raw request body: compute the expected HMAC (such as HMAC-SHA256) using the provider's webhook signing secret and the exact unparsed byte payload before JSON serialization changes whitespace or key order.
  • Use constant-time digest comparison: compare the computed signature and header signature with `crypto.timingSafeEqual` rather than `===` to prevent byte-by-byte timing side channels.
  • Enforce timestamp tolerance and event idempotency: reject webhook deliveries whose signed timestamp is older than a short window (such as 5 minutes), and store processed `event_id` values in a unique table or cache key so replayed deliveries do not trigger duplicate credits or state changes.

Securing customer-configured outbound webhooks against SSRF

When your product allows customers to register custom webhook URLs for event notifications, treat every target URL as an untrusted SSRF vector. Require `https://` URLs, disable automatic HTTP redirects on your webhook delivery client, resolve DNS inside a custom socket dialer that blocks loopback, RFC 1918 private networks, and cloud metadata IPs (`169.254.169.254`), enforce strict response timeouts and payload size limits, and dispatch outbound webhooks from an isolated worker network with no access to internal control planes.

Verify inbound webhook HMAC signatures over the raw body with constant-time comparison, record event IDs for idempotency, and block private IPs on outbound webhooks.

Run a vulnerability scan on your website.

Verify your domain and use MyPentest to check for supported web and API weaknesses. Review findings and coverage; a clean scan does not rule out every CVE.