Verify the bytes a webhook signed
Parsing and authenticating a delivery belong at different points in the request path.
Preserve the input
GitHub documents HMAC-SHA256 verification using the webhook secret and payload, compared with X-Hub-Signature-256. The comparison should use a constant-time operation. Verification depends on the received payload bytes; parsing JSON and serializing it again can change whitespace or representation.
Place a bounded raw-body capture before middleware that transforms the content. After authenticating the delivery, parse it and validate the event shape needed by the handler. A valid signature establishes knowledge of the shared secret; the application still needs to decide which event and repository it will act on.
A small diagnostic fixture
For an original local fixture, sign a harmless JSON body containing a Unicode label. Verify the unchanged bytes, then change whitespace without changing the parsed object. The first should pass and the second should fail. Also check a missing header and a wrong secret. These cases distinguish body handling problems from event-processing problems without exercising a production webhook.
Keep the fixture secret separate from deployed credentials. Log a delivery reference and the verification result, never the signing secret or an unrestricted request body.
Separate retries from trust
A correctly signed request can be delivered more than once. Our suggested handler design records the delivery identity and business operation separately so that a retry can be acknowledged without repeating its effect. Define retention and concurrent-delivery behavior explicitly; a process-local set is not a durable agreement between workers.