1. Webhooks
  2. Signing Webhook Requests (HMAC)

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:

Header Value
X-Stubber-Timestamp The time of the request, in whole seconds since the Unix epoch, e.g. 1767225600.
X-Stubber-Nonce A value used only once, 16 to 128 characters of A-Z a-z 0-9 _ -. A UUID works well.
X-Stubber-Signature v1= followed by the signature in hexadecimal, e.g. v1=49b8dac5….

What gets signed

The signature is the HMAC-SHA256 of this string, keyed with the shared secret, written as lowercase hexadecimal:

        v1:{timestamp}:{nonce}:{METHOD}:{path and query}:{body}

      
  • timestamp and nonce: 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.

Node.js
        import { createHmac, randomUUID } from "node:crypto";

const secret = process.env.STUBBER_WEBHOOK_SECRET;
const url = new URL("https://webhooks.stubber.com/im/2026-01-01-ABCD-1234/receive_payment");
const body = JSON.stringify({ order_id: "A-1001", amount: 250 });

const timestamp = Math.floor(Date.now() / 1000).toString();
const nonce = randomUUID();
const signature = createHmac("sha256", secret)
  .update(`v1:${timestamp}:${nonce}:POST:${url.pathname}${url.search}:${body}`)
  .digest("hex");

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Stubber-Timestamp": timestamp,
    "X-Stubber-Nonce": nonce,
    "X-Stubber-Signature": `v1=${signature}`,
  },
  body,
});

      
Python
        import hashlib, hmac, json, os, time, uuid
from urllib.parse import urlsplit

import requests

secret = os.environ["STUBBER_WEBHOOK_SECRET"]
url = "https://webhooks.stubber.com/im/2026-01-01-ABCD-1234/receive_payment"
body = json.dumps({"order_id": "A-1001", "amount": 250}, separators=(",", ":")).encode()

parts = urlsplit(url)
path = parts.path + (f"?{parts.query}" if parts.query else "")
timestamp = str(int(time.time()))
nonce = str(uuid.uuid4())
signed = f"v1:{timestamp}:{nonce}:POST:{path}:".encode() + body
signature = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()

response = requests.post(url, data=body, headers={
    "Content-Type": "application/json",
    "X-Stubber-Timestamp": timestamp,
    "X-Stubber-Nonce": nonce,
    "X-Stubber-Signature": f"v1={signature}",
})

      
bash
        SECRET="$STUBBER_WEBHOOK_SECRET"
URL_PATH="/im/2026-01-01-ABCD-1234/receive_payment"
BODY='{"order_id":"A-1001","amount":250}'

TIMESTAMP=$(date +%s)
NONCE=$(uuidgen)
SIGNATURE=$(printf '%s' "v1:$TIMESTAMP:$NONCE:POST:$URL_PATH:$BODY" \
  | openssl dgst -sha256 -hmac "$SECRET" -hex | sed 's/^.* //')

curl -X POST "https://webhooks.stubber.com$URL_PATH" \
  -H "Content-Type: application/json" \
  -H "X-Stubber-Timestamp: $TIMESTAMP" \
  -H "X-Stubber-Nonce: $NONCE" \
  -H "X-Stubber-Signature: v1=$SIGNATURE" \
  --data-binary "$BODY"

      

Test values

Check your implementation against these. With the secret whsec_test_8f2c1a:

Input Value
Timestamp 1767225600
Nonce 4f9c2b7e-1d3a-4e8b-9a6c-0b5d7e2f1a3c
Method POST
Path /im/2026-01-01-ABCD-1234/receive_payment
Body {"order_id":"A-1001","amount":250}

The string to sign is

        v1:1767225600:4f9c2b7e-1d3a-4e8b-9a6c-0b5d7e2f1a3c:POST:/im/2026-01-01-ABCD-1234/receive_payment:{"order_id":"A-1001","amount":250}

      

and the header is

        X-Stubber-Signature: v1=49b8dac59261823b53e436c3a611e065740b1222c770f9f3175dfdb95b336572

      

The same request as a GET to /im/2026-01-01-ABCD-1234/receive_payment?order_id=A-1001, without a body, signs

        v1:1767225600:4f9c2b7e-1d3a-4e8b-9a6c-0b5d7e2f1a3c:GET:/im/2026-01-01-ABCD-1234/receive_payment?order_id=A-1001:

      

to v1=6b0d947c4167f29b72647c3aaf620af12b49877a5c40f18b1c0514bc723ea7e8.

How Stubber checks a request

In this order:

  1. The three headers are present and well formed.
  2. The timestamp is within the action's tolerance of Stubber's clock, 5 minutes unless set otherwise. Keep your clock synchronized (NTP).
  3. The signature matches, compared in constant time.
  4. 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:

Status error.message Meaning
401 hmac_headers_missing One of the three headers is missing.
401 hmac_headers_invalid The timestamp isn't whole seconds, or the nonce has the wrong length or characters.
401 timestamp_outside_tolerance The timestamp is too far from Stubber's clock, in either direction.
401 invalid_signature The signature doesn't match: a different secret, or the method, path, query or body differ from what was signed.
401 replayed_request The nonce was used before. Send every request with a new nonce, and sign it again.
415 hmac_multipart_not_supported File uploads can't be signed.
503 replay_check_unavailable Stubber couldn't check the nonce. Retry with a new nonce.

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:

        X-Stubber-Signature: v1=<signature with the new secret>,v1=<signature with the old secret>

      

To rotate without downtime:

  1. Start sending both signatures, with the old and the new secret.
  2. Set the new secret on the credential in Stubber.
  3. Stop sending the signature made with the old secret.