Verify Razorpay’s signature against the exact webhook body and make processing safe when an event is retried.
Build the example
Read raw bytes before any JSON parsing. Compute HMAC-SHA256 with the webhook secret and compare digests with a constant-time comparison after validating length. After verification, use the Razorpay event ID to deduplicate delivery, then apply the verified state update and record the event atomically where possible. Checkout signature verification has a separate message format.
Exercise a valid signed event whose order amount differs from the fixture’s amount. The signature check should pass and the transition should refuse the update. Also sign malformed JSON using the dummy secret and confirm the handler handles parsing safely. These checks distinguish verified delivery from acceptable content and an eligible business effect.
Signed delivery and durable effects
Verify Razorpay’s signature against the exact webhook body and make processing safe when an event is retried.
Example
- Verify
hash the original bytes
- Deduplicate
look up the verified event reference
- Commit
record event and apply the effect atomically where possible
record event and apply the effect atomically where possible
Watch the failure boundary
Verify signatures before inspecting the event as trusted data. A webhook sender can retry after your response is lost, so a memory-only set does not provide durable deduplication. Store the provider event reference and an internal effect reference. If side effects happen outside the database, give their delivery path its own idempotency key.
Verify the behavior
Use synthetic payloads with a dummy secret. Verify an original payload, reject the same JSON reserialized with different spaces, and replay the original event. Expect one durable business effect. A signature proves authenticity of the bytes, while amount, currency and payment state still need to match the operation.
Sources
- Razorpay: validate webhook signatures
- Node.js: crypto
- Public project: TechNightCity
- Public project: Amanat
Technical references checked .



