All problems

Webhook Signature Breaks After JSON Re-serialization

Level 2 · node · Security · Webhook raw-body signature verification error

Scenario

A payment partner sends webhook signatures as an HMAC over the original request-body bytes. Simple JSON requests work, but operations reports 401 responses when the partner sends valid JSON with different whitespace or key ordering. The HTTP adapter supplies both rawBody and the parsed body to the controller, which calls a signature verifier before the event service.

Requirements

- Verify the signature against the rawBody exactly as sent by the partner - A JSON webhook with a valid signature is processed and returns 204 - Valid signatures remain accepted when the original JSON contains whitespace or a different key order - An invalid signature returns 401 and does not store an event - After successful verification, pass the parsed body to the service

Acceptance criteria

  • A valid signature for basic JSON is accepted
  • JSON containing whitespace is accepted with a valid signature for those original bytes
  • JSON with a different key order is accepted with a valid signature for those original bytes
  • An invalid signature returns 401 and stores no event
  • A successful webhook stores the parsed event data