---
title: "Can anyone post to your webhook URL? How to check the signature"
description: "Your webhook URL is open to the whole internet, so before you trust any request, compute the HMAC signature from the secret and the raw body, and compare it with the one in the header using a constant-time comparison."
url: https://ihsanalapsi.dev/articles/webhook-signature-verification
lang: en
date: 2026-11-19
updated: 2026-11-19
tags: ["App security", "Web development"]
author: Ihsan Alapsi (إحسان العبسي)
---
# Can anyone post to your webhook URL? How to check the signature

You have a URL like /webhooks/payments, the payment service sends it "order opened" or "payment received", and your code turns on the subscription as soon as the request arrives. But the URL is on the internet, and anyone who knows it can send it the same JSON. In this article you will see how to make sure the request really comes from the service, with an example for GitHub webhooks.

## What is a webhook signature?

A webhook signature is a value the service computes from a secret shared between you and it, and from the request content, and sends in a header. You compute the same value on your side, and if they match, the request came from the service and nobody changed it on the way.

The computation uses HMAC, a method that mixes the secret with the text and produces a fingerprint. Someone without the secret cannot produce the same fingerprint.

## How does GitHub sign its requests?

GitHub puts the signature in a header called X-Hub-Signature-256, and the value always starts with sha256=.

According to the [page on validating webhook deliveries in the GitHub docs](https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries):

- The signature is computed from the webhook secret and the payload, as an HMAC hex digest.
- An older header called X-Hub-Signature uses HMAC-SHA1, and is only there for legacy purposes.
- The comparison is never a plain `==`, it is a constant-time method like `crypto.timingSafeEqual`.
- The payload and headers must not be modified before verification.

## Where do most people get it wrong?

The most common mistake is computing the signature on the JSON after the framework parsed it into an object, not on the raw body as it arrived.

When you turn the object back into text, spaces and field order may change, so the fingerprint comes out different. Then people try two wrong fixes: they turn verification off "for now", or they compare with `==`. The first opens the URL to anyone, and the second is exactly what the GitHub docs say never to do.

## How do you write the check in Node.js?

You read the body raw, compute the HMAC with the secret, compare in constant time, and only then parse.

```javascript
import crypto from 'node:crypto';
import express from 'express';

const app = express();

function isValidSignature(rawBody, header, secret) {
  if (!header) return false;
  const expected = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(rawBody)
    .digest('hex');
  const a = Buffer.from(expected);
  const b = Buffer.from(header);
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

app.post('/webhooks/github', express.raw({ type: 'application/json' }), (req, res) => {
  const header = req.get('X-Hub-Signature-256');
  if (!isValidSignature(req.body, header, process.env.GITHUB_WEBHOOK_SECRET)) {
    return res.status(401).end();
  }
  const event = JSON.parse(req.body.toString('utf8'));
  // from here on, the request is trusted
  res.status(204).end();
});
```

`express.raw` keeps `req.body` as the bytes that arrived, so the fingerprint is computed on the same thing GitHub signed, and parsing comes after the check, not before it.

## How do you test that the code is right?

You test the code with the values the same GitHub page gives: a known secret and payload, with the signature that must come out.

```
secret:    It's a Secret to Everybody
payload:   Hello, World!
signature: sha256=757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17
```

1. Call `isValidSignature` with these values, and the result must be `true`.
2. Change one character in the payload, and the result must become `false`.
3. Send a request with no header to the URL, and it must return `401`.

## Where do you start now?

The lesson for you as a developer: a webhook URL is a door on the internet, so never trust a request before you match the signature on the raw body with a constant-time comparison, because the secret is the one thing the attacker does not have.

Open every endpoint that receives webhooks in your app, and check whether its first line verifies the signature. If the secret itself is in your code, see [how GitHub blocks pushing secrets](/articles/github-push-protection-secrets). If you want to see why an endpoint has to check everything itself, there is the [IDOR article](/articles/idor-object-access-check). And if you want someone to test your whole app, there is [Muhassan](/muhassan).

How many endpoints in your app receive webhooks, and do all of them verify the signature?

## FAQ

**If my webhook URL is secret and long, is that enough?**

No. The URL shows up in logs, in the service settings and with anyone who has access, and it does not prove who sent the request. The signature does.

**Why does my signature never match even though the secret is right?**

Usually because the framework parsed the JSON into an object before you computed it. Compute the signature on the raw body as it arrived, then parse.

**I use a payment service, not GitHub. Is it the same?**

The idea is the same at most services: a shared secret and an HMAC signature in a header. The header name and signature format differ, so read that service's own docs.
