A webhook body can contain the same JSON values after formatting yet fail its signature check. For a signature calculated over the received body, the exact bytes matter. Spaces and line breaks added for readability become different input to the verification operation.
Keep the received body for verification and make a separate display copy when inspecting it. This walkthrough uses fictional event data and a deliberately public demonstration key, not a real delivery or account credential.
Confirm which input the webhook provider signs
Start with the integration’s own signing contract. GitHub’s delivery-validation guidance describes HMAC-SHA256 in X-Hub-Signature-256, a sha256= prefix and UTF-8 payload handling. Its examples verify the original body before further processing, and its troubleshooting section says to keep the payload and headers unmodified before verification.
This guide models that raw-body requirement. Other providers can assemble a signing input from a timestamp, a body or additional fields; follow their documented construction. The HMAC and plain SHA-256 guide covers the separate choice of cryptographic operation.
Compare a readable copy with the original body
Use this fictional one-line JSON, without a final newline:
{"event":"note.created","id":17}
Paste it into Paste your JSON in the JSON Formatter and Validator. Choose 2 spaces for Indent, leave Minify and Sort keys alphabetically unchecked, and select Format JSON. The current result is:
{
"event": "note.created",
"id": 17
}
The original has 32 UTF-8 bytes; the formatted copy has 41. Both parse to the same values in this example, but their body bytes differ. The formatter parses and rebuilds JSON. It does not verify webhook signatures. MDN documents the serialization spacing parameter that introduces indentation and line breaks.
A readable copy is useful for inspection. Preserve the original separately, as the API example formatting guide recommends when exact payload bytes matter.
Reproduce the signature mismatch with public test data
For this demonstration, the public key text is public-format-demo-key. The following local Python calculation uses the original body bytes:
import hashlib
import hmac
key = b"public-format-demo-key"
body = b'{"event":"note.created","id":17}'
print("sha256=" + hmac.new(key, body, hashlib.sha256).hexdigest())
Python’s HMAC module supplies the keyed calculation. This example prints:
sha256=1ee3a1c5b9c57065b4460cb3f6ba3521b983328ef78525b10504468a6cb3e725
We sent four real HTTP requests to an isolated local receiver. It collected the raw body before parsing, verified HMAC with the public demonstration key using a constant-time comparison, and processed only accepted bodies. Independent Python checks confirmed the recorded request bytes and signatures.
| Body sent | Signature sent | Observed local result |
|---|---|---|
| Original, 32 bytes | Signature of the original body | 200; accepted and processed |
| Formatted, 41 bytes | Same original signature | 401; rejected before processing |
| Formatted, 41 bytes | Separately calculated signature of the formatted body | 200; accepted and processed |
| Original plus one line feed, 33 bytes | Same original signature | 401; rejected before processing |
All four bodies represent the same parsed JSON values. The third row is a separate demonstration sender signing different bytes; it is not a repair to apply inside a receiver. These statuses belong to the synthetic receiver, not a test of GitHub deliveries or a complete production integration.
Keep verification ahead of parsing and formatting
- Capture the original request body early. Use your framework’s documented raw-body access before middleware replaces it with a parsed object or rebuilt JSON.
- Verify the documented signing input. Use the provider’s supported verifier with the configured secret and received signature, including its documented safe comparison behavior.
- Parse and process after verification succeeds. Keep any pretty-printed view as a separate inspection copy.
- Trace transformations when verification fails. Check middleware, proxies, newline handling and serialization between receipt and verification. Compare exact input bytes; equal lengths alone do not prove equality.
For remaining mismatches, check the configured key, algorithm and header against the integration documentation.