· webhooks

Verify Webhook Signatures in Request Inspector

Inspect methods, paths, headers, and status codes to catch invalid HMAC or signing secrets on local Stripe, GitHub, Shopify, and Slack webhooks, then replay payloads.

By InstaWormhole team, Engineering

Verify Webhook Signatures in Request Inspector

Webhook handlers often reject valid payloads with an HTTP 400 or 401 during local development. A trailing newline in an environment variable, a JSON body parsed before verification, or a signing secret copied from the wrong place is enough to break a signature check. Triggering live events from a provider dashboard over and over is a slow way to find out which one it was.

A tunnel with a request inspector gives you the method, path, headers, status and (if you keep it) body of each delivery. This guide covers why signature checks fail, what each provider sends, how to check signatures with the InstaWormhole Request Inspector, and how to replay a captured request after you fix your handler.

Why local webhook signature verification fails

Stripe, GitHub, Shopify and Slack all sign deliveries with HMAC-SHA256 and a shared secret. Your server recomputes the digest from the incoming request and compares it with the value in the signature header. If the two differ, the request must be rejected.

Four causes account for most local failures:

  • Body parser mutation: Frameworks such as Express often parse JSON before your webhook route runs. Re-serializing the parsed object does not reliably reproduce the exact bytes the provider signed, so the digest no longer matches. Shopify’s documentation lists parsing the body before verification as a common issue and tells you to place verification middleware before any body parser.
  • Wrong signing secret: A secret copied from a different endpoint, app or environment will never match. Shopify, for example, signs with your app’s client secret rather than a separate webhook secret. GitHub does not send X-Hub-Signature-256 at all if no secret is configured on the webhook.
  • Header and prefix handling: Header names are case-insensitive, and Slack’s documentation warns against assuming a particular letter case. Signature values also carry prefixes you must handle: sha256= for GitHub, v0= for Slack, and a t=...,v1=... structure for Stripe.
  • Timestamp tolerance: Stripe and Slack include a timestamp in the signed material. Stripe’s libraries reject timestamps outside a five-minute default tolerance (configurable), and Slack’s documentation recommends rejecting requests more than five minutes from local time. A drifting clock or a late replay fails the check even when the secret is correct.

Compute the HMAC over the raw request body bytes before any JSON middleware touches them.

Provider signature headers and algorithms

ProviderSignature headerTimestamp in signed materialFormat
StripeStripe-SignatureYes, t= inside the same headert=<unix seconds>,v1=<hex>, HMAC-SHA256 over {t}.{raw body}
GitHubX-Hub-Signature-256Nosha256=<hex>, HMAC-SHA256 over the raw body
ShopifyX-Shopify-Hmac-Sha256NoBase64 HMAC-SHA256 over the raw body
SlackX-Slack-SignatureYes, X-Slack-Request-Timestampv0=<hex>, HMAC-SHA256 over v0:{timestamp}:{raw body}

Stripe

Stripe signs the timestamp from the header, a literal dot, and the raw payload with your endpoint’s signing secret, and sends the result as the v1 value. During a secret rotation the header can carry more than one v1 entry, so compare against each. Stripe’s own libraries handle all of this for you; see Stripe’s webhook documentation.

GitHub

GitHub computes an HMAC hex digest of the payload with your webhook’s secret token, and the value always starts with sha256=. The older X-Hub-Signature header uses HMAC-SHA1 and is included only for legacy purposes, so use the -256 header. GitHub’s guidance is to compare with a constant-time function such as crypto.timingSafeEqual. See Validating webhook deliveries.

Shopify

Shopify sends a Base64-encoded HMAC-SHA256 of the raw body, keyed with your app’s client secret. A hex digest will never equal a Base64 header, so encode your digest as Base64 before comparing. Shopify also sends an X-Shopify-Webhook-Id header that is unique per delivery, which you can use to detect duplicates. It expects a 200-range response, treats redirects as errors, and applies a one-second connection timeout and a five-second timeout for the whole request. See Shopify’s delivery verification guide.

Slack

Slack joins the literal v0, the X-Slack-Request-Timestamp value and the raw body with colons, signs that string with your app’s signing secret, and sends v0=<hex digest>. Because the timestamp is inside the signed string, a captured request cannot be replayed indefinitely against a strict verifier. See Verifying requests from Slack.

What to look for in the inspector

For each captured request, check the following.

  • Method and path: Confirm the request arrived as a POST and that the path matches the route your app mounts, including any prefix such as /api/webhooks/stripe. A redirect response is a failure for Shopify, so avoid trailing-slash redirects on webhook routes.
  • Signature header: Confirm Stripe-Signature, X-Hub-Signature-256, X-Shopify-Hmac-Sha256 or X-Slack-Signature actually arrived. A missing header usually points to a missing secret on the provider side or a proxy that dropped it.
  • Content type: Slack slash commands and interactive payloads are form-encoded, while Events API deliveries and most other providers send JSON. Either way, sign-check the raw body, not a parsed copy.
  • Status and who answered: The inspector shows the status and whether your app or InstaWormhole itself produced the answer. Your own handler decides which code it returns, so choose them deliberately. In the example below, 400 means a malformed or stale request and 401 means a signature mismatch. A 500 often means an exception in your verification code, such as passing an undefined secret to crypto.createHmac() because an environment variable did not load.

If InstaWormhole answered instead of your app, the request never reached your handler. Tunnel Doctor reports a code for each layer. CONNECTOR_OFFLINE and CONNECTOR_UNAVAILABLE mean the connector is not running or did not take the request, and ORIGIN_UNREACHABLE means your app is not answering on the --origin address.

Step by step: tunnel, inspect, verify

The inspector records requests only for durable tunnels, so create one in the dashboard rather than using a quick address.

Step 1: Connect your app

For a quick, temporary address, the connector’s quick form takes a port:

npx @instawormhole/connector 3000

That form is not recorded in the inspector. For webhook debugging, create a durable tunnel in the dashboard and copy the command from its Connect an app section. It has this shape:

npx @instawormhole/connector run --relay wss://relay.instawormhole.site --origin 127.0.0.1:3000 --stored-device --tunnel <tunnel id>

Add your webhook path to the tunnel’s public address and enter that URL in the provider’s dashboard, for example https://example.instawormhole.site/webhooks/stripe. Use a test or sandbox mode: the InstaWormhole docs advise against pointing a provider’s live mode at a tunnel on your laptop. Stripe’s own listen command also forwards events to a local address and works as an alternative for Stripe-only testing.

Step 2: Keep request bodies

By default the inspector does not store bodies. Open the inspector and choose Keep bodies before you send the test event. New requests then keep the first 64 KiB of the request and response body for 24 hours. Bodies are not redacted, so turn capture off when you are done and delete requests you no longer need. The inspector does redact sensitive header values such as authorization and cookie, and query string values in the path.

Step 3: Verify the raw body in your handler

This Express example reads raw bytes on webhook routes and uses constant-time comparison. For production Stripe handling, prefer the official SDK’s stripe.webhooks.constructEvent().

import crypto from "node:crypto";
import express from "express";

const app = express();

// Raw bytes on webhook routes only; no JSON parser before these handlers.
app.use("/webhooks", express.raw({ type: "*/*" }));

function timingSafeMatch(expected, actual) {
  const a = Buffer.from(expected, "utf8");
  const b = Buffer.from(actual, "utf8");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

const TOLERANCE_SECONDS = 300;

function isFresh(timestamp) {
  const age = Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp));
  return Number.isFinite(age) && age <= TOLERANCE_SECONDS;
}

// Stripe: HMAC-SHA256 over "{t}.{raw body}", compared with each v1 value.
app.post("/webhooks/stripe", (req, res) => {
  const header = req.get("Stripe-Signature") || "";
  const secret = process.env.STRIPE_WEBHOOK_SECRET;

  const pairs = header.split(",").map((part) => part.split("="));
  const timestamp = pairs.find(([key]) => key === "t")?.[1];
  const signatures = pairs.filter(([key]) => key === "v1").map(([, value]) => value);

  if (!timestamp || signatures.length === 0 || !isFresh(timestamp)) {
    return res.status(400).json({ error: "Malformed or stale Stripe signature" });
  }

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.`)
    .update(req.body)
    .digest("hex");

  if (!signatures.some((sig) => timingSafeMatch(expected, sig))) {
    return res.status(401).json({ error: "Invalid Stripe signature" });
  }
  return res.status(200).json({ received: true });
});

// GitHub: "sha256=" + hex HMAC of the raw body.
app.post("/webhooks/github", (req, res) => {
  const received = req.get("X-Hub-Signature-256") || "";
  const expected =
    "sha256=" +
    crypto
      .createHmac("sha256", process.env.GITHUB_WEBHOOK_SECRET)
      .update(req.body)
      .digest("hex");

  if (!timingSafeMatch(expected, received)) {
    return res.status(401).json({ error: "Invalid GitHub signature" });
  }
  return res.status(200).json({ received: true });
});

// Shopify: Base64 HMAC of the raw body, keyed with the app's client secret.
app.post("/webhooks/shopify", (req, res) => {
  const received = req.get("X-Shopify-Hmac-Sha256") || "";
  const expected = crypto
    .createHmac("sha256", process.env.SHOPIFY_CLIENT_SECRET)
    .update(req.body)
    .digest("base64");

  if (!timingSafeMatch(expected, received)) {
    return res.status(401).json({ error: "Invalid Shopify HMAC" });
  }
  return res.status(200).json({ received: true });
});

// Slack: "v0=" + hex HMAC of "v0:{timestamp}:{raw body}".
app.post("/webhooks/slack", (req, res) => {
  const received = req.get("X-Slack-Signature") || "";
  const timestamp = req.get("X-Slack-Request-Timestamp") || "";

  if (!isFresh(timestamp)) {
    return res.status(400).json({ error: "Stale Slack timestamp" });
  }

  const expected =
    "v0=" +
    crypto
      .createHmac("sha256", process.env.SLACK_SIGNING_SECRET)
      .update(`v0:${timestamp}:${req.body.toString("utf8")}`)
      .digest("hex");

  if (!timingSafeMatch(expected, received)) {
    return res.status(401).json({ error: "Invalid Slack signature" });
  }
  return res.status(200).json({ ok: true });
});

app.listen(3000, () => {
  console.log("Webhook server listening on port 3000");
});

In Next.js App Router route handlers, read the body with await request.text() rather than await request.json() before verifying.

Step 4: Let the inspector check the signature

The inspector can also tell you whether a captured request carries a valid signature for your secret. This is available on Starter and higher, on durable tunnels.

  1. Open the tunnel and find Webhook signatures.
  2. Choose the provider (Stripe, GitHub, Slack or Shopify), paste the signing secret and save. The secret must be at least 6 characters, is stored encrypted, and is never shown again after you save it.
  3. Send a webhook from the provider and open it in the inspector. The request detail shows whether the signature is valid.

To confirm the check works, send a request with a wrong signature and see that the inspector reports it as not valid. Choose Remove under Webhook signatures to delete the secret. This check only reports on captured requests. It does not stop an invalid request from reaching your app, so your handler must still verify signatures itself.

If the inspector says the signature is invalid, compare the secret in your .env file with the one in the provider dashboard. A common slip is pasting an API key or OAuth client ID where a webhook signing secret belongs. Also check that express.raw() is registered before any express.json() that could match the same route.

Replay a captured request after the fix

After you fix your handler, you do not need to create a new checkout session, push a commit or place a new order. Select the request in the inspector, choose Replay, review the dialog, and confirm.

The dialog shows the method, path, headers and, if it was kept, the body. You can edit them. Because bodies are only stored when Keep bodies was on at capture time, a request captured without a body replays without one and will fail signature verification. Check the dialog for the signature header and the body before you confirm.

Keep the following in mind:

  • The replay goes to the tunnel’s public address and on to your app, and it carries an X-Instawormhole-Replay header.
  • You can replay once every 5 seconds, and each replay is recorded in the workspace audit log.
  • The replayed request appears as a new row in the inspector.
  • Replay is not available on a password-protected tunnel and is not offered for WebSocket requests.
  • If the request creates or changes something, replaying it can do that again.

Timestamps during replay

GitHub and Shopify do not put a timestamp inside the signed material, so a captured delivery still verifies later against the same secret. Stripe and Slack bind a timestamp into the signature. If you replay one after the five-minute window, your freshness check will reject it even though the HMAC itself matches. Either replay within the window or temporarily widen the tolerance in development only, and keep strict enforcement in production.

Best practices

  • Document secret formats: Keep a .env.example showing the expected shape, such as STRIPE_WEBHOOK_SECRET=whsec_..., so teammates notice when they paste an API key by mistake.
  • Do not echo digests: Return a generic error on signature failure instead of the expected HMAC, even in staging.
  • Test idempotency: After a request passes, replay it a few times and confirm your handler deduplicates on a delivery identifier such as the Stripe event ID (evt_...), X-GitHub-Delivery or X-Shopify-Webhook-Id.
  • Use test modes: Point only test or sandbox webhooks at a local tunnel.