Webhook Signature Validation Guide: HMAC, Replay Protection, Retries, and Idempotency
webhooksAPI securityHMACevent-driven systemsdeveloper tools

Webhook Signature Validation Guide: HMAC, Replay Protection, Retries, and Idempotency

VValidator Cloud Editorial Team
2026-11-13
8 min read

A practical webhook security checklist covering raw payloads, HMAC verification, replay protection, retries, and idempotent event handling.

Webhook signature validation is the first control that should run when an event reaches your application. This guide provides a reusable checklist for preserving the raw payload, verifying HMAC or asymmetric signatures, blocking replayed requests, handling retries safely, and making webhook processing idempotent.

Overview

A webhook endpoint accepts requests initiated by another system rather than by a user directly interacting with your application. That makes the endpoint useful, but it also means your application must decide whether each request is authentic, fresh, and safe to process.

Secure webhook handling has several separate responsibilities:

  • Authenticity: confirm that the request was signed by the expected provider.
  • Integrity: confirm that the body and relevant headers were not changed after signing.
  • Freshness: reject old requests that could be copied and submitted again.
  • Availability: respond predictably so the provider can retry temporary failures.
  • Idempotency: ensure that a valid event produces the intended result only once, even when delivery is repeated.

These controls work together. A valid signature does not automatically prevent replay, and replay protection does not make an unsigned request trustworthy. Treat verification as a gate before business logic, and treat duplicate handling as a separate property of the event-processing workflow.

Provider documentation is the authority for the exact header names, signature format, canonicalization rules, hash algorithm, timestamp units, and retry behavior. The checklist below is designed to help you implement and review those requirements without assuming that every provider uses the same scheme.

Checklist by scenario

When receiving a new webhook provider

  1. Record the contract. Document the endpoint URL, event types, signing headers, algorithm, encoding, timestamp format, delivery identifier, and expected response codes.
  2. Use HTTPS. Terminate TLS correctly and confirm that proxies do not replace, normalize, or remove headers needed for verification.
  3. Capture the raw body. Verify the signature against the exact bytes received. Do not parse and re-serialize JSON before verification, because whitespace, key ordering, escaping, or number formatting may change the signed message.
  4. Reproduce the provider's signed message. A common pattern is a timestamp, a separator, and the raw body. Do not infer this structure; implement the provider's documented construction exactly.
  5. Compute the expected signature. Retrieve the secret from a protected secret store, use the specified digest and encoding, and compare values with a constant-time comparison function.
  6. Validate the timestamp. Require a timestamp when the provider's scheme supports one, convert it to a known unit, and reject requests outside your documented acceptance window.
  7. Check a unique delivery value. If the provider supplies an event ID, delivery ID, or nonce, use it as part of replay and duplicate protection.
  8. Only then parse and process the event. Schema validation, event authorization, and business logic should follow successful signature verification.

When implementing HMAC webhook verification

HMAC uses a shared secret to produce a message authentication code. Both the sender and receiver know the secret, but the secret must never be sent in the request. A typical verification sequence is:

  1. Read the raw request body without transforming it.
  2. Read the signature and timestamp headers exactly as specified.
  3. Construct the signed message in the documented format.
  4. Calculate the HMAC using the required hash function and secret.
  5. Decode or normalize the received signature only as the provider requires.
  6. Compare the calculated and received values in constant time.
  7. Reject missing, malformed, expired, or mismatched values before business processing.

Do not log the secret, the complete authorization header, or sensitive payload data while troubleshooting. Log a safe request identifier, verification result, event type, and failure category instead.

When the provider uses an asymmetric signature

With an asymmetric scheme, the provider signs with a private key and your service verifies with a public key or certificate. This avoids sharing a signing secret with every receiver, but introduces key-distribution and rotation concerns. Confirm how your application obtains trusted keys, how key identifiers select a key, how certificates are validated, and what happens when a key is retired.

A certificate or public-key check is not a substitute for validating the signed content. The key must be trusted, the signature must match the raw message, and any required certificate validity or revocation checks must follow the provider's documented model. For broader certificate concepts, see the Digital Signature Verification API Guide.

Signature-method comparison

MethodWhat the receiver needsPrimary review points
HMACA shared secretRaw bytes, exact message construction, constant-time comparison, secret rotation
Asymmetric signatureA trusted public key or certificateKey selection, trust chain, rotation, signature format, certificate checks
Mutual TLSA client-certificate trust configurationCertificate identity, expiry, revocation approach, proxy behavior, renewal
Unsigned token or basic authenticationA credential in the requestTransport security, credential rotation, replay exposure, and whether content integrity is protected

These methods are not interchangeable. A bearer token may identify a caller without proving that the body was not modified. Use the provider's supported signing model and document its limitations.

When preventing replayed requests

A replay occurs when an attacker or faulty intermediary captures a previously valid request and submits it again. A timestamp window reduces the useful lifetime of a captured request, but it does not stop two submissions made within that window.

  • Reject timestamps that are missing, malformed, or outside an intentionally chosen clock-skew window.
  • Keep application clocks synchronized and monitor clock drift.
  • Store a short-lived record of accepted event IDs, nonces, or signature-plus-timestamp combinations.
  • Make the uniqueness check atomic so two concurrent requests cannot both pass it.
  • Choose retention long enough to cover the accepted timestamp window and expected delivery behavior.
  • Return a generic verification failure rather than revealing whether a specific ID has already been seen.

Replay protection should not depend only on an IP address. Providers may use multiple delivery addresses, and network identifiers can be shared or changed.

When handling retries and duplicate events

Webhook delivery is commonly at-least-once: a provider may send the same event again after a timeout, connection failure, or non-success response. Your handler should therefore be safe to run more than once.

  1. Verify the signature and freshness before creating side effects.
  2. Use the provider's stable event or delivery ID as the idempotency key where available.
  3. Store the key with a unique database constraint or equivalent atomic operation.
  4. Separate receipt from processing when work may take longer than the provider's response timeout.
  5. Return success only when the event has been durably accepted, or follow the provider's documented acknowledgement model.
  6. Make downstream actions idempotent too. A database insert guard does not by itself prevent two payment, email, or fulfillment actions triggered by later code.

For related guidance on retry policies, timeouts, and idempotency, review the Validation API Reliability Guide.

What to double-check

  • Raw payload handling: Does the framework expose the original bytes before JSON parsing? Are middleware components consuming or rewriting the body?
  • Header parsing: Are duplicate headers, casing, whitespace, delimiters, and multiple signature values handled according to the provider's rules?
  • Encoding: Is the signature hexadecimal, Base64, URL-safe Base64, or another representation? Are you comparing decoded bytes or text consistently?
  • Algorithm selection: Is the algorithm fixed by configuration rather than accepted from untrusted input?
  • Secret and key rotation: Can the service verify during an overlap period with an old and new credential without weakening validation?
  • Event authorization: After authentication, is the event type allowed for this endpoint and tenant?
  • Payload validation: Does the event conform to the expected schema, and are unknown or dangerous fields handled deliberately? The JSON Schema Validation Guide covers compatibility and error handling considerations.
  • Failure responses: Do malformed requests receive a controlled client error, while temporary internal failures remain distinguishable for retry purposes?
  • Observability: Can operators correlate a delivery ID across ingress logs, queue records, processing attempts, and downstream actions without storing sensitive content?

Test the complete path with altered whitespace, reordered JSON keys, invalid signatures, expired timestamps, duplicate deliveries, concurrent submissions, rotated credentials, oversized bodies, and provider retry behavior. These cases often reveal errors that a single successful fixture does not.

Common mistakes

  • Parsing before verifying: Re-serialization can change the signed representation.
  • Using ordinary string equality: Prefer a constant-time comparison designed for authentication values.
  • Trusting a timestamp without storing uniqueness: A timestamp window limits age, not repeated use within that window.
  • Performing side effects before acknowledgement control: A later verification or validation failure cannot undo an email, refund, shipment, or account change.
  • Treating every non-success response as permanent failure: This can cause avoidable event loss. Align responses with the provider's retry model.
  • Using an event ID only in application code: Enforce uniqueness in durable storage so concurrent workers cannot process the same event twice.
  • Logging secrets or complete payloads: Debugging data can become a second exposure path. Redact credentials and minimize personal or transactional data.
  • Accepting an algorithm named by the request: The server should select an allowed algorithm from trusted configuration.
  • Ignoring operational limits: Apply request-size limits, rate controls, queue limits, and timeouts without bypassing signature verification.

When to revisit

Revisit this checklist before onboarding a webhook provider, changing event handlers, rotating secrets or keys, modifying API gateway middleware, or introducing a queue between receipt and processing. It also belongs in pre-release testing when a provider changes its signing scheme, headers, SDK, event format, timestamp recommendation, or HTTP retry conventions.

Use the following incident-review template after a rejected, replayed, duplicated, or unexpectedly delayed event:

  1. Identify the delivery: record the provider, endpoint, event type, delivery ID, and approximate receipt time.
  2. Classify the failure: signature mismatch, stale timestamp, duplicate, schema error, transport error, processing error, or downstream side effect.
  3. Check the raw request path: compare gateway, framework, queue, and application representations of the body and headers.
  4. Review credential state: confirm which secret, public key, certificate, or key ID was active during delivery.
  5. Trace retries: establish whether the provider retried, your service timed out, or an internal worker repeated the job.
  6. Confirm side effects: verify that idempotency controls prevented duplicate external actions.
  7. Record the corrective action: update tests, runbooks, dashboards, configuration, or provider documentation references.

Keep this article and your implementation checklist versioned alongside the webhook integration. The durable principle is simple: preserve the exact message, authenticate it with the provider's specified method, reject stale or repeated deliveries, and make every accepted event safe to process more than once.

Related Topics

#webhooks#API security#HMAC#event-driven systems#developer tools
V

Validator Cloud Editorial Team

Technical Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.