opyebWebhookLab

Guides · Fundamentals

When the signature never matches: the raw body problem

2026-11-29 · 7 min read

One-line answer

Most signature mismatches happen because the body was parsed and re-serialized, so the bytes differ from what was signed. Keep the bytes from before parsing.

What the raw body is

The raw body is the exact bytes of the HTTP request body, not the object a JSON parser produced. Signatures cover those bytes, so a single changed space produces a completely different HMAC.

These two strings represent the same object, but their signatures differ.

JSON
{"id":"evt_1","amount":4900}
{ "id": "evt_1", "amount": 4900 }

Five common mutations

MutationWhat changesWhere it happens
JSON re-serializationwhitespace, key order, number formatframework body parser
CRLF ↔ LFline-break bytesproxies, gateways, text-mode forwarding
Added trailing newlinefinal \neditors, curl -d, copying logs
Unicode escapingé ↔ \u00e9language JSON libraries
Character encodingUTF-8 ↔ legacy code pagesold proxies, wrong Content-Type

Any one of them makes the recomputed signature differ from the header. Far more often than not the signing logic is correct and the input changed.

Keeping the raw body by stack

StackHow to keep the raw body
Expressapply express.raw({ type: "*/*" }) to the webhook route only
Next.js App Routerconst raw = await request.text() and verify that string
FastAPIread await request.body() first
Flaskrequest.get_data() before parsing
Goio.ReadAll(r.Body) and verify those bytes

A global express.json() registered before the webhook route has already consumed the raw body. Scope the raw parser to the webhook path and mind the middleware order.

Diagnostic order

  1. Check the byte count and line endings of the received body.
  2. Keep the header fixed and retry verification with CRLF→LF or trailing whitespace removed.
  3. If it is JSON, also try the parsed-and-re-serialized form.
  4. Whichever variant matches tells you which layer rewrote the body; fix that layer.

Matching a variant in production is first aid, not a fix. Preserve the original bytes and use variant matching only while diagnosing.

The body comparison tool shows the first differing byte between two bodies.

Open the signature verifier

Frequently asked questions

Does logging the body help debugging?

It helps, with care. Copying from logs can change line endings or whitespace, and personal data may be captured. Log the byte count and a hash alongside it.

What about Content-Encoding: gzip?

The sender signs the uncompressed body. The receiver must verify the decompressed bytes and confirm decompression did not alter them.

It works locally but fails in production. Why?

A proxy or API gateway in front of the app may rewrite the body or headers. Confirm that it forwards bytes unchanged, especially character and transfer encodings.

This guide follows the signing schemes published by GitHub, Stripe, Slack, Shopify and Toss Payments.

← Guides