When an agent platform calls a developer's server to run an agent, both sides need proof. The server must know the request came from the platform and was not replayed; the platform must know it is talking to the right endpoint. Payment providers solved this years ago: Stripe signs every webhook with HMAC-SHA256 and its libraries reject timestamps more than 5 minutes old. The same pattern, formalised by the open Standard Webhooks specification, fits AI agents well.
In this guideFollows you as you read
Why agents need signed requests
An agent endpoint does real work: it reads customer data, drafts messages, maybe charges credits. If anyone who learns the URL can call it, an attacker can trigger runs, drain budgets or inject instructions. HTTPS alone proves the server's identity to the caller, not the caller's identity to the server.
A shared secret and a signature solve this. The platform signs each request with a secret only it and the developer hold; the developer's server recomputes the signature and rejects anything that does not match. OWASP's webhook guidance lists signature verification and replay protection as the core controls.
What to sign
Sign the exact bytes sent, plus anything that must not change. Stripe signs the timestamp, a full stop and the raw request body. The Standard Webhooks specification signs the message ID, the timestamp and the body, each separated by a full stop, and sends three headers: webhook-id, webhook-timestamp and webhook-signature.
Including the message ID lets the receiver detect duplicates; including the timestamp lets it reject old requests. Never sign a parsed and re-serialised body, because whitespace or key order can change and break verification. Stripe's documentation is explicit that the raw body must be used.
| Part | Stripe | Standard Webhooks |
|---|---|---|
| Signed content | timestamp.body | id.timestamp.body |
| Algorithm | HMAC-SHA256, hex | HMAC-SHA256, base64 (v1) |
| Headers | Stripe-Signature with t= and v1= | webhook-id, webhook-timestamp, webhook-signature |
| Secret format | whsec_ prefix | whsec_ prefix, 24 to 64 random bytes |
Verifying on the receiving server
Verification has four steps, and the order matters. Read the raw body before any framework parses it. Recompute the HMAC over the same signed content with your secret. Compare the result with the received signature using a constant-time comparison, so response timing does not leak how many characters matched. Only then check that the timestamp is within your tolerance.
The example below is illustrative; use your platform's official library where one exists.
import crypto from "node:crypto";
// Illustrative verifier for a signed agent request
export function verify(rawBody: string, headers: Record<string, string>, secret: string, toleranceSec = 300) {
const ts = Number(headers["x-timestamp"]);
const sig = headers["x-signature"] || "";
const expected = crypto.createHmac("sha256", secret).update(`${ts}.${rawBody}`).digest("hex");
const a = Buffer.from(expected), b = Buffer.from(sig);
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) return false;
return Math.abs(Date.now() / 1000 - ts) <= toleranceSec;
}Replay protection and duplicates
A valid signed request can be captured and sent again. The timestamp limits that window: Stripe's libraries default to 5 minutes and warn never to set a tolerance of 0, which disables the check. Keep your server clock synced with NTP so honest requests are not rejected.
Inside the window, use the message ID as an idempotency key. Store IDs you have processed and skip repeats. Stripe advises the same for its events, because a webhook can arrive more than once, and also warns that events may arrive out of order, so never rely on order.
Retries, timeouts and quick responses
Senders retry when they do not get a 2xx response. Stripe retries live events for up to three days with exponential backoff; the Standard Webhooks specification suggests a multi-day schedule with jitter and notifying the receiver by another channel if delivery keeps failing. Receivers should acknowledge quickly and do slow work in a queue.
For agent runs that take longer than a timeout, return an accepted status with a run ID and report the result later, rather than holding the connection open. Standard Webhooks suggests timeouts of roughly 15 to 30 seconds and payloads under about 20 KB, with large files linked rather than embedded.
Rotating secrets without downtime
Secrets leak through logs, screenshots and old laptops, so plan to rotate them. Stripe lets an old secret stay valid for up to 7 days while a new one is introduced, and signs each event once per active secret. Standard Webhooks allows several space-separated signatures in one header for the same reason.
On the receiving side, accept a request if any active secret verifies it, then remove the old secret once traffic shows only the new one. Show a secret to a developer once, store only what you need to verify, and never write secrets into logs.
A checklist for agent marketplaces
Platforms that let third parties run agents should enforce these rules for every listing.
- HTTPS only, with no redirects followed
- Every request signed over a timestamp, a run ID and the raw body
- A tolerance of a few minutes and clock sync on both sides
- Run IDs stored and duplicates ignored
- Workspace identifiers hashed so developers never see raw customer IDs
- Secrets shown once, rotatable, and never logged
- Agent output treated as untrusted input and validated before use
How XDQ applies this
The XDQ Store follows this pattern: each paid run is sent to the developer's HTTPS endpoint as a signed request with a timestamp, a run ID and a hashed workspace ID, and the platform expects a JSON answer back. Anything an agent produces still waits for a person's approval before it reaches a customer.
Frequently asked questions
How do signed webhooks work?
The sender computes an HMAC, usually HMAC-SHA256, over the timestamp and raw body using a shared secret, and sends it in a header. The receiver recomputes the HMAC with the same secret, compares it in constant time and rejects requests that do not match or are too old.
How do you prevent webhook replay attacks?
Include a timestamp in the signed content and reject requests outside a short tolerance, such as the 5 minutes Stripe's libraries use by default. Also store each message ID and ignore repeats, because a valid request can be resent within the window.
What is the Standard Webhooks specification?
An open specification for webhook signing. It defines webhook-id, webhook-timestamp and webhook-signature headers, signs the ID, timestamp and body with HMAC-SHA256, and gives guidance on retries, timeouts, payload size and secret rotation.
Why must the raw request body be used for verification?
The signature covers the exact bytes sent. If a framework parses and re-serialises the JSON, whitespace or key order can change, so the recomputed signature will not match even for a genuine request.
Sources
- Receive Stripe events in your webhook endpoint, Stripe, 2026
- Standard Webhooks specification, Standard Webhooks, 2026
- Webhook Security Cheat Sheet, OWASP, 2026
- Timestamp tolerance, Svix, 2026
- Replay attack, Svix, 2026
- HMAC, Wikipedia, 2026



