Webhooks
Signing Webhook Requests (HMAC)
Explains how to sign requests to a Stubber webhook with HMAC-SHA256, a timestamp and a nonce. Useful for integrations that call HMAC-protected webhooks and need to build, test and rotate their signatures.
A webhook with HMAC authentication only accepts requests signed with a secret shared between Stubber and the caller. The signature covers the request itself and a timestamp and nonce, so a request can't be altered, sent to another stub or action, or replayed.
This page is the standard callers follow. To turn it on for an action, see HMAC authentication. It's available on implicit webhooks (/im/{stubref}/{action_name}).
Headers
Every request carries three headers:
What gets signed
The signature is the HMAC-SHA256 of this string, keyed with the shared secret, written as lowercase hexadecimal:
timestampandnonce: exactly as sent in the headers.METHOD: the HTTP method in capitals, e.g.POST.path and query: the path the request is sent to, with its query string, exactly as sent, e.g./im/2026-01-01-ABCD-1234/receive_payment?order_id=A-1001. No scheme or host.body: the request body, byte for byte as sent. Empty for a request without a body (e.g.GET).
Sign the exact bytes you send. A JSON body serialized once for signing and again for sending can differ (key order, spacing), and the signature then fails.
Supported bodies: JSON (application/json), form data (application/x-www-form-urlencoded) and raw bytes (application/octet-stream). File uploads (multipart/form-data) can't be signed and are refused.
Examples
Each example sends a signed JSON POST.
Test values
Check your implementation against these. With the secret whsec_test_8f2c1a:
The string to sign is
and the header is
The same request as a GET to /im/2026-01-01-ABCD-1234/receive_payment?order_id=A-1001, without a body, signs
to v1=6b0d947c4167f29b72647c3aaf620af12b49877a5c40f18b1c0514bc723ea7e8.
How Stubber checks a request
In this order:
- The three headers are present and well formed.
- The timestamp is within the action's tolerance of Stubber's clock, 5 minutes unless set otherwise. Keep your clock synchronized (NTP).
- The signature matches, compared in constant time.
- The nonce hasn't been used before with this secret. Stubber remembers a nonce for twice the tolerance; after that its timestamp is too old to be accepted anyway.
A request is only accepted once it passes all four. A request that fails the signature check doesn't use up its nonce.
Errors
Rejected requests are answered with a JSON body whose error.message names the reason:
To retry a request, sign it again with a new timestamp and nonce.
Rotating the secret
X-Stubber-Signature can hold several signatures, separated by commas. A request is accepted when any of them matches:
To rotate without downtime:
- Start sending both signatures, with the old and the new secret.
- Set the new secret on the credential in Stubber.
- Stop sending the signature made with the old secret.