STARA INSIGHTS · SEO
Webhook Security: Signature Validation, Replay, and Redelivery
Secure webhooks with signature verification, replay protection, processing state, and a reliable redelivery checklist.
Webhooks notify systems when events occur. An externally reachable endpoint must verify the sender, record receipt reliably, and handle redelivery. A valid signature alone does not ensure that a business action happens only once or that events arrive in order.
Why do webhooks need multiple layers of protection?
An endpoint that accepts JSON and immediately changes data can receive forged payloads, lose events during a failure, or repeat a completed transaction. This is both a security and a reliability problem. Start with the provider's contract: signature method, event identity, response deadline, ordering, and how deliveries can be inspected and redelivered. These rules vary by provider.
Illustration: an order system receives a payment webhook. The signature is valid, but the server fails after updating the order and before the sender receives a response. Another delivery for the same event may arrive. Without idempotency, the application could trigger fulfillment twice.
Verify the signature before processing the payload
Use HTTPS and certificate verification, then follow the provider's documented algorithm and header. For example, GitHub documents HMAC-SHA256 validation using a secret and the original body. A proxy or parsing step that changes the body before verification can cause validation to fail. Compare signatures using a platform-provided constant-time function.
Store secrets in an appropriate secret store, restrict access, and plan rotation with the provider. Do not put secrets in URLs, source code, or logs. Reject missing or invalid signatures and record the reason without exposing credentials. Signature verification establishes integrity and possession of the secret under the provider's scheme; it does not replace authorization for each business action.
Distinguish replay, redelivery, and duplicate events
A replay resends a captured message, potentially by an unauthorized party. Legitimate redelivery may be necessary after a failure. The two can look alike, so handling must take identity and processing status into account.
Store the provider's identifier and define its scope, for example per provider and endpoint. GitHub states that a redelivery retains the same X-GitHub-Delivery value. This is a GitHub rule, not a guarantee for every provider. If the provider supports signed timestamps, apply a tolerance according to its documentation and monitor clock synchronization. A timestamp alone does not prevent duplicates within that window; a signature alone does not prevent replay either.
Design states such as received, processing, completed, and failed. Use a uniqueness constraint and transactions to prevent two workers from making the same decision concurrently. If an ID is complete, respond according to the contract without repeating the business effect. If it is still processing or failed, apply a defined safe retry policy. Effects in another system still need their own idempotency or reconciliation; a local database transaction does not automatically cover an external service. See the consumer idempotency guide.
Acknowledge promptly and process reliably
Separate receipt from long-running work. After verifying the signature and event type, durably store the payload or its reference with the ID and status, then return success according to the contract. A worker processes it in the background. Do not acknowledge success before receipt is durable: if the process stops after the response but before safe storage, the event can be lost.
As a provider-specific example, GitHub requires a 2xx response within 10 seconds and suggests a queue for asynchronous work. Do not treat that number as universal. A queue adds operational dependencies; plan capacity, retention, monitoring, and recovery around business needs.
Handle failures and out-of-order events
Not every failure merits endless retries. Separate temporary faults from unsupported payloads and configuration errors. Use bounded retries with delays, failed-item handling, alerts, and an audited redelivery procedure. Operators should be able to see the ID, time, status, and correlation without exposing sensitive content.
Do not rely on arrival order unless the provider guarantees it. Consider source versions or state and reconciliation through the official API where available. Do not reject a legitimate redelivery merely because it was received before if processing failed: retain enough state to distinguish completion from recovery. Agree on the procedure with business owners, especially for irreversible effects.
Production checklist
- Document the provider's algorithm, headers, event identity, timeout, retries, and limitations.
- Test the original body, invalid or missing signatures, secret rotation, and log redaction.
- Test simultaneous deliveries, redelivery after success, and crashes before and after commit.
- Acknowledge success only after durable receipt; test database and queue failures.
- Test late and out-of-order events, worker failure, recovery, and reconciliation with the source.
- Assign alert ownership, retention, operator access, and an audited recovery procedure.
FAQ
Is HTTPS enough?
HTTPS protects the connection, but the endpoint still needs to verify that the message comes from a party holding the valid secret, according to the provider's mechanism.
Does a signature prevent duplicate transactions?
No. The signature validates the message; idempotency and recorded state control the effects of repeated processing.
Does every provider retry webhooks automatically?
Do not assume so. Check each provider's policy and prepare monitoring and recovery procedures.
When is an event complete?
Define completion by confirmed business effects, including external dependencies. A successful HTTP receipt does not necessarily mean the business work is complete.
Next steps
If your integration involves webhooks, queues, and multiple systems, review provider contracts and failure scenarios with business and technical owners. StaraSolution Services offers technical consulting and API and system integration to discuss those needs.