toolqik

06 · Generators

Webhook Secret Generator

Signing secrets for webhooks, with verification snippets.

Runs in your browser
Format
Strength
Signing secret

  
verify-webhook.js

  

About this tool

A webhook secret is a shared key that the sender uses to sign each webhook with HMAC-SHA256, and the receiver uses to check that signature. If the signature matches, the request really came from the sender and the body wasn’t changed. A 256-bit random secret is the standard choice, and every secret here comes from your browser’s secure random generator.

When you need to generate one

  • Providers that let you set the secret. GitHub and Razorpay, for example, ask you to type a secret when you add a webhook. Generate one here, paste it into their dashboard, and store the same value in your app’s environment (for example WEBHOOK_SECRET).
  • Providers that give you one. Stripe and others generate the secret for you (Stripe’s start with whsec_). Use theirs; you don’t need this tool.
  • You send webhooks. If your product notifies other systems, generate a separate secret for each customer endpoint, show it to them once, and let them rotate it.

Which format to choose

  • whsec_ + Base64: the format of the Standard Webhooks specification. The prefix makes the value easy to recognise and lets secret scanners spot leaks. The key is the Base64 part, decoded.
  • hex: plain 0-9a-f, safe to paste anywhere, including dashboards that reject symbols.
  • base64url: shorter, and still safe in URLs and .env files.

Verify incoming webhooks

The Node.js and Python snippets in the tool above show the receiving side. They read the secret from the WEBHOOK_SECRET environment variable, compute the HMAC over the raw request body, and compare in constant time. Always verify the raw bytes before parsing JSON.

Those snippets use the secret as a plain text key, which is how GitHub and Razorpay sign. For a whsec_ secret in the Standard Webhooks format, the key is the decoded Base64 part, as in the signing example below. Sender and receiver must agree on this, or every signature will fail. To check a real request by hand, capture it with the webhook tester and recompute the signature with the HMAC generator.

Sign webhooks you send

If you’re the sender, include a unique message ID and a timestamp, and sign them together with the body. The receiver can then reject old timestamps (replay attacks) and skip duplicate IDs. This example follows the Standard Webhooks format, so receivers can use its official libraries to verify it:

const crypto = require('node:crypto');

// Standard Webhooks style: sign "id.timestamp.body" with the decoded secret.
async function sendWebhook(url, secret, event) {
  const body = JSON.stringify(event);
  const timestamp = Math.floor(Date.now() / 1000);
  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const signature = crypto
    .createHmac('sha256', key)
    .update(event.id + '.' + timestamp + '.' + body)
    .digest('base64');

  await fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'webhook-id': event.id,
      'webhook-timestamp': String(timestamp),
      'webhook-signature': 'v1,' + signature,
    },
    body,
  });
}

Webhook security checklist

  • Use at least 256 bits of randomness, and a different secret per endpoint.
  • Verify every request. Reject it if the signature is missing or wrong.
  • Reject timestamps older than about five minutes to block replays.
  • Make handlers idempotent: providers retry, so the same event can arrive twice.
  • Store secrets in environment variables or a secret manager, never in code.
  • When rotating, accept both the old and the new secret for a short overlap period.

FAQ

How do I generate a webhook secret?

Use a cryptographically secure random generator, like this page or openssl rand -hex 32, to create at least 32 random bytes. Paste it into the provider’s webhook settings and store the same value in your app’s environment.

How long should a webhook secret be?

32 random bytes (256 bits) is the standard. That is 64 hex characters or 43 base64url characters. Longer secrets work too but add little for HMAC-SHA256.

Why use a constant-time comparison?

A normal string comparison stops at the first different character. An attacker can time that to guess a valid signature byte by byte. timingSafeEqual and hmac.compare_digest prevent this.

Why does my signature never match?

The most common cause is verifying a re-serialized JSON body instead of the raw bytes. Whitespace and key order change the HMAC. Test with the HMAC Generator and the Webhook Tester.

What is the whsec_ prefix?

A convention used by several providers to mark a value as a webhook signing secret. It makes the secret easy to recognise and helps scanners detect leaks.

esc
↑↓ navigate↵ open