The mistake
A Razorpay webhook handler that never checks X-Razorpay-Signature; computes the HMAC over JSON.stringify(req.body) after express.json() has parsed it; compares the signature with ===; or has the webhook secret written into the code.
Why it is dangerous
Anyone can POST a forged payment.captured event to a public webhook URL. Razorpay signs the exact bytes it sends; JSON.stringify produces different bytes, so valid events fail at random and the check gets switched off. == / === on strings stops at the first differing byte, so the response time leaks how much of a guessed signature is right. A hard-coded secret lets anyone with the code sign their own events.
How to fix it
Compute HMAC-SHA256 of the raw body with the webhook secret, compare it with X-Razorpay-Signature in constant time, and stop the request when it fails:
// Express: raw body on this route, registered before express.json()
app.post("/api/webhooks/razorpay", express.raw({ type: "application/json" }), handler)
# Python
client.utility.verify_webhook_signature(payload.decode(), signature, secret)Use crypto.timingSafeEqual / hmac.compare_digest, and keep the secret in an environment variable.
What this checker looks for
This page runs webhook-check, which reads
route handlers in Next.js, Express, Fastify, Hono, FastAPI, Flask and Django. The rules most relevant to this page:
| Rule | What it finds |
|---|---|
WHK001 | Webhook handler does not verify the signature |
WHK002 | Signature checked against parsed / re-serialized JSON |
WHK003 | Signature compared with == instead of a constant-time comparison |
WHK004 | Hard-coded webhook signing secret |
WHK005 | Signature verification failure is ignored |
WHK007 | Webhook events are not de-duplicated |
Every finding has a rule id, a severity, file:line, the offending line (secrets masked),
why it matters and how to fix it. Run webhook-check rules for the full list.