A Razorpay webhook that doesn't check the X-Razorpay-Signature header acts on any JSON posted to it, so someone can mark an order paid without paying.
What you see
Orders or subscriptions turn paid when nobody paid, or the webhook route accepts any request sent to it.
Why it happens
The webhook route reads the event and updates the database without first proving Razorpay sent it. Razorpay signs each event with the webhook secret you chose in its Dashboard, in the X-Razorpay-Signature header, and only that signature shows the event is real.
How to fix it
- Read the raw request body as text before parsing it: the signature is over the exact bytes Razorpay sent.
- Check it with
validateWebhookSignature(rawBody, signature, RAZORPAY_WEBHOOK_SECRET)from the razorpay package, or compare an HMAC-SHA256 of the raw body, keyed with the secret, to the header. Return 400 when it doesn't match. - Only then act on
payment.captured,order.paidand thesubscriptionevents, and make handling the same event twice harmless: Razorpay retries. - Keep the webhook secret in an environment variable, never in the code.
Or ask your AI tool to fix it
Paste this into Lovable, Bolt, v0, Replit or Cursor:
Make the Razorpay webhook route read the raw request body, verify it against the X-Razorpay-Signature header with validateWebhookSignature and RAZORPAY_WEBHOOK_SECRET, return 400 when verification fails, and only then update the database. Handling the same event twice must not change anything.
The full page, with the request ready to copy, is at launchpad.axonscape.com/fix/razorpay-webhook-not-verified. I work on Launchpad by Axonscape, which runs a free launch check for apps built with AI tools: it finds this and the other things that break at launch, from a public GitHub repo or a .zip of the code, and keeps nothing.