﻿# GitHub webhook HMAC verifies the original request body

Verify GitHub webhook HMAC against the original request body, keeping payload encoding, signature decoding and constant-time digest comparison distinct from JSON interpretation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-github-webhook-hmac-original-body/
Language: en

## Preserve the received material before JSON parsing

The [GitHub validation guide](https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries) demonstrates verifying the original request body before parsing its JSON. Whitespace, escaped characters and line endings can change during reconstruction even when application fields remain equivalent. A proposed receiver therefore preserves raw body material at the framework boundary. Parsing can still happen after validation, but a serializer cannot reconstruct evidence of the exact representation that arrived merely from the resulting object.

## Match the digest contract and payload format

The [delivery header reference](https://docs.github.com/en/webhooks/webhook-events-and-payloads) defines X-Hub-Signature-256 as an HMAC digest over the request body using the webhook secret. It also describes JSON and URL-encoded payload delivery formats. The signed material is the delivered body, not whichever nested field an application later extracts. An editorial integration record should include the selected content type and signature scheme. Do not compare a raw hexadecimal digest directly with an undecoded prefixed header as if they were identical representations.

## Keep text decoding from silently changing the body

GitHub's troubleshooting guidance covers UTF-8 payloads, Unicode and modification by proxies or load balancers. A receiver that performs character replacement, newline normalization or JSON pretty-printing before verification has changed its verification input. A proposed local fixture can preserve one Unicode payload in several transport representations and identify exactly where a framework converts bytes to text. The goal is to explain a mismatch, not to relax verification until a modified payload passes.

## Compare valid digest representations deliberately

The [Node.js crypto reference](https://nodejs.org/api/crypto.html) defines timingSafeEqual over byte-backed inputs and requires equal byte lengths. Different lengths produce an error, while surrounding code still needs its own careful handling. A proposed verifier first validates the header's structure and decodes the documented digest representation, then compares like-for-like bytes using the chosen runtime's supported primitive. Malformed input should become an authentication failure rather than an uncaught application exception or an ordinary string-comparison shortcut.

## Separate authenticated bytes from event processing

A valid body HMAC establishes the documented authenticity and integrity check; it does not decide the meaning of an event action or whether downstream work was already completed. Preserve parsed-event interpretation separately after validation. [Contract fixtures](/journal/provider-golden-contract-fixtures/) can cover original and modified bodies, while [request correlation](/journal/provider-request-id-trace-context/) distinguishes a tracing value from cryptographic evidence. This article describes verification of public protocol examples and creates no webhook endpoint, secret or delivery.
