A webhook endpoint is a public URL that accepts unauthenticated HTTP POST requests from the internet. That is the entire contract. Every event-driven workflow that starts from a payment, a pull request, or an order update is, at the network level, an open door that trusts whatever arrives at it.
Most integration guides stop at "paste the URL into the provider's dashboard and the workflow will run." That is enough for a demo. It is not enough for a workflow that creates invoices, provisions accounts, or updates a CRM, because nothing in that setup proves the request came from the provider, that it was not recorded and sent again later, or that the same event will not be processed twice.
This article walks through the three controls that turn a webhook URL into a trustworthy ingestion layer: signature verification, replay protection, and idempotent processing. We will look at how Stripe, GitHub, and Shopify actually sign their requests, where each control belongs in a workflow, and how to build the pattern with the Webhook Trigger, Crypto, Router, and Redis nodes in puq.ai.
The Threat Model of a Public Endpoint
Before adding controls, it helps to be precise about what can go wrong. A webhook-triggered workflow is exposed to four distinct failure modes:
- Forged requests: Anyone who learns the URL can send a crafted payload that looks like a legitimate
payment_succeededororder_createdevent. - Replayed requests: An attacker, or a misconfigured proxy, captures a valid request and sends it again minutes or days later. The payload and signature are both genuine.
- Duplicate deliveries: Providers deliver events at least once, not exactly once. Network timeouts and retries mean the same event can legitimately arrive two or more times.
- Out-of-order deliveries: An
updatedevent can arrive before thecreatedevent it refers to. Stripe, for example, documents that it does not guarantee delivery order.
Signature verification addresses the first. A signed timestamp addresses the second. Idempotency keys address the third and limit the damage of the second. Ordering requires a separate design decision, which we cover at the end.
There is also a cost dimension that is easy to overlook. On puq.ai, every workflow run counts as an execution regardless of whether it succeeds or fails. Rejected forgeries still consume your execution quota, which is why the webhook URL itself should be treated as a credential: keep it out of client-side code and public repositories, and rotate it if it is exposed.
How Providers Sign Webhooks
Almost every major provider uses the same primitive: an HMAC (Hash-based Message Authentication Code) computed with SHA-256 over the request body, using a secret shared between the provider and the receiver. The details differ in ways that matter.
Stripe sends a Stripe-Signature header containing a timestamp (t) and one or more signatures (v1). The signed message is not the body alone. It is the timestamp, a literal period, and the raw body concatenated: {t}.{raw_body}. The HMAC is hex-encoded. Because the timestamp is part of the signed content, an attacker cannot change it without invalidating the signature. Stripe's official libraries reject events whose timestamp is older than five minutes by default.
GitHub sends an X-Hub-Signature-256 header with the value sha256= followed by the hex-encoded HMAC of the raw body. GitHub does not include a timestamp in the signed content. Each delivery carries a unique X-GitHub-Delivery GUID, which is the value to use for deduplication.
Shopify sends an X-Shopify-Hmac-Sha256 header containing a base64-encoded HMAC of the raw body, keyed with the app's client secret. Shopify also sends an X-Shopify-Webhook-Id header that identifies the delivery and can be used to detect duplicates.
Three practical conclusions follow from this comparison:
- The output encoding differs (hex for Stripe and GitHub, base64 for Shopify), so the verification step must be configured per provider.
- The signed message differs. Stripe signs
{t}.{body}, while GitHub and Shopify sign the body alone. - Only Stripe binds a timestamp to the signature. For GitHub and Shopify, replay protection depends on deduplicating delivery IDs.
The Raw Body Requirement
The most common reason a correctly configured verification fails is that the HMAC is computed over the wrong bytes.
Providers sign the exact byte sequence they send. If any layer between the network and your verification step parses the JSON and serializes it again, the result can differ in whitespace, key order, number formatting, or Unicode escaping. The data is semantically identical, but the HMAC is not.
"Signature verification is a byte-level comparison. A payload that has been parsed and re-serialized is a different message, even when every field is the same."
In puq.ai, the Webhook Trigger captures the incoming headers, query parameters, and body and passes them into the execution. Before you wire the body into a verification step, open a test execution in the execution details view and confirm that the value you are mapping is the unmodified request body, not a re-serialized object. Test with a real delivery from the provider rather than a hand-written curl request, since your own test payload will not reveal formatting differences.
Building the Verification Step
With the raw body available, verification is a short sequence of nodes placed directly after the trigger and before any node that has side effects.
Step 1: Store the secret as a Variable. The signing secret belongs in puq.ai Variables, not hardcoded in a node configuration. This keeps it out of exported workflow definitions and lets you rotate it without editing the workflow.
Step 2: Construct the signed message. For GitHub and Shopify, the message is the raw body. For Stripe, extract t from the Stripe-Signature header and build the string {t}.{raw_body}.
Step 3: Compute the expected HMAC. The HMAC Generation node in the Crypto category takes a hash algorithm, an input text, a secret key, and an output encoding. Select SHA-256, map the message from Step 2 as input, map the secret from Variables, and choose hexadecimal for Stripe and GitHub or base64 for Shopify.
Step 4: Compare and branch. Use a Router node with two branches. The first branch continues when the computed value matches the signature from the header (for GitHub, compare against the header value with the sha256= prefix removed). The Otherwise branch handles everything else: log the rejection and stop the execution before any downstream system is touched.
A note on comparison: in application code, signatures should be compared with a constant-time function such as Node.js crypto.timingSafeEqual, because a standard string comparison returns early on the first mismatched character and can, in principle, leak timing information. If you perform the comparison in a Code Executor step rather than a Router condition, apply the same discipline. Remote timing attacks against HMAC comparisons are difficult to exploit over a network, but constant-time comparison costs nothing and removes the question entirely.
For reference, the core of a Stripe-style check in plain Node.js looks like this:
const crypto = require("crypto");
function verifyStripeStyle(rawBody, header, secret, toleranceSec = 300) {
const parts = Object.fromEntries(
header.split(",").map((kv) => kv.split("="))
);
const timestamp = Number(parts.t);
const age = Math.floor(Date.now() / 1000) - timestamp;
if (!Number.isFinite(age) || age > toleranceSec) return false;
const expected = crypto
.createHmac("sha256", secret)
.update(`${timestamp}.${rawBody}`)
.digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(parts.v1 || "");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
Note the length check before timingSafeEqual, which throws if the two buffers differ in length. Note also that this simplified parser reads a single v1 value; during secret rotation, Stripe can include more than one signature in the header, which is covered below.
Replay Protection
A valid signature proves the request was produced by someone holding the secret. It does not prove the request is fresh.
For providers that sign a timestamp, replay protection is a time-window check. After the signature passes, compare the signed timestamp with the current time and reject anything outside a tolerance window. Five minutes is the common default. The window should be wide enough to absorb clock drift and provider queueing, and no wider. Because the timestamp is inside the signed content, an attacker cannot move an old request into the window.
For providers that do not sign a timestamp, a time window is not available, because any timestamp header could be altered without breaking the signature. Replay protection then reduces to deduplication: record every delivery ID you have processed and refuse to process the same ID twice. This is the same mechanism as idempotency, which is why the two controls are usually implemented together.
Idempotent Processing
Providers retry deliveries when they do not receive a timely 2xx response. GitHub, for example, expects a response within 10 seconds. A workflow that is slow to respond, or that times out after already creating a record, will see the same event again. Without idempotency, the second delivery creates a second invoice, a second Slack alert, or a second CRM contact.
The pattern has three parts:
- Choose a stable key. Use the provider's event or delivery identifier: the Stripe event
id, theX-GitHub-DeliveryGUID, or theX-Shopify-Webhook-Id. Do not hash the whole payload, because a legitimate retry may carry identical content while two distinct events could, in edge cases, share content. - Claim the key atomically. Before any side effect, record the key in a shared store with a single atomic operation that tells you whether you were first. A separate "check, then write" sequence is not safe, because two concurrent deliveries can both pass the check before either one writes. In Redis, an atomic increment works well for this:
INCRcreates the key if it does not exist and returns the new value, so a result of 1 means this is the first delivery, and anything higher means the event has already been claimed. - Plan for key cleanup. Dedup keys only need to outlive the provider's retry window. Stripe, for example, retries for up to three days. Keep keys under a dedicated prefix such as
webhook:dedup:so they are easy to find and remove later.
puq.ai includes a Redis node in its Developer Tools category, which makes it possible to keep the deduplication store outside the workflow itself. Use its Increment Key action with the delivery ID as the key (for example webhook:dedup:{event_id}), placed after signature verification and before the first node that writes to an external system. Follow it with a Router: the first branch continues when the returned value equals 1, and the Otherwise branch records the duplicate and ends the execution without side effects.
The Redis node's actions do not include setting an expiry on a key, so dedup keys persist until they are removed. Each key holds only a small integer, so storage grows slowly, but for high-volume endpoints you can add a scheduled workflow that uses Get Keys with the webhook:dedup:* pattern and Delete Key to clear old entries, or apply an expiry policy on the Redis server itself.
One subtle case deserves attention. If the claim succeeds but a later step fails, the key is already stored and the provider's retry will be discarded as a duplicate. The simplest fix is to use the Redis node's Delete Key action in the failure branch, so the next retry can claim the key again. This is safe only if the steps that ran before the failure can be repeated without harm; if they cannot, make those steps idempotent on their own (for example, by checking whether the record already exists before creating it).
Choosing the Right Endpoint Mode
puq.ai exposes two endpoint types for every webhook-triggered workflow. The Async endpoint returns a response immediately and runs the workflow in the background. The Sync endpoint keeps the request open until the workflow finishes and returns its output.
For third-party webhooks, the Async endpoint is usually the correct choice. Providers enforce short response timeouts and interpret slow responses as failures, which triggers retries and increases duplicate traffic. With the Async endpoint, the provider receives an immediate response, and verification, deduplication, and processing happen inside the execution.
The trade-off is visibility. Because the response is sent before verification runs, a rejected signature does not appear as a failed delivery in the provider's dashboard. Rejections need to be visible somewhere else: route the Otherwise branch of the verification Router to a notification or a log, and review failed and rejected runs in puq.ai's execution history. A sudden increase in rejected signatures is often the first sign of a rotated secret that was not updated, or of someone probing the endpoint.
Reserve the Sync endpoint for request-response integrations where the caller needs the workflow's result, such as an internal service that submits data for validation and waits for the answer.
Rotating Secrets Without Downtime
Signing secrets need to be rotated: when a team member with access leaves, when a secret appears in a log, or on a fixed schedule. A naive rotation (replace the secret in the provider, then replace it in the workflow) creates a window in which valid events fail verification.
The safer sequence is an overlap period:
- Add the new secret as a second Variable while the old one remains in place.
- Update the verification step to accept a signature that matches either secret.
- Rotate the secret in the provider. Stripe supports rolling an endpoint secret while keeping the previous one valid for a period, and during that period it can include a signature for each active secret in the
Stripe-Signatureheader. - After the overlap window ends and no events signed with the old secret are arriving, remove the old Variable and the second comparison.
Version History in puq.ai is useful here, because the change to the verification step is recorded and can be rolled back if the new configuration rejects legitimate traffic.
Handling Out-of-Order Events
Signature verification, replay protection, and idempotency make each individual event trustworthy. They do not put events in order. An invoice.updated can be processed before the invoice.created it modifies, especially when retries are involved.
There are two dependable strategies. The first is to treat the webhook as a notification rather than a source of truth: when an event arrives, use its identifier to fetch the current state of the object from the provider's API and act on that state. The second is to compare a version or timestamp field on the object against the last value you stored, and skip updates that are older than what you already have. Either approach is easier to reason about than trying to buffer and reorder events inside a workflow.
A Reference Pipeline
Putting the pieces together, a hardened webhook-triggered workflow has a consistent shape:
- Webhook Trigger (Async endpoint): Receives the request and returns immediately.
- Signature verification: Builds the signed message from the raw body, computes the HMAC with the secret from Variables, and compares it with the header value.
- Freshness check: Rejects signed timestamps outside the tolerance window, for providers that sign one.
- Idempotency claim: Atomically increments a Redis key derived from the delivery ID, and exits if the returned value is greater than 1.
- Business logic: Fetches current state where ordering matters, then performs the side effects.
- Rejection and failure branches: Log the reason and notify the team, without touching downstream systems.
None of these steps is complex on its own. The value comes from their order: nothing with a side effect runs until the request has been authenticated, confirmed as fresh, and claimed as new.
Building Secure Event-Driven Workflows
Webhooks are the simplest way to make workflows react to events in other systems, and they are also the part of an automation stack most directly exposed to the internet. Treating every incoming request as untrusted until it is verified, fresh, and new is what separates a working integration from a reliable one.
If you are building event-driven workflows on puq.ai, start with the verification pattern above on your highest-impact webhook, such as payments or account provisioning, and extend it to the rest once it is in place. Create a free puq.ai account to build your first verified webhook workflow.