Forgebox
← All guides

Guide · Updated 2026-11-30

Using HMAC to Verify Webhooks

How shared-secret message authentication protects webhook endpoints from forged requests, plus an implementation checklist for encoding and comparison.

Related tool: HMAC Generator

The core idea

HMAC lets two parties verify that a message was produced by someone holding a shared secret and that the message was not altered in transit. Many webhook providers sign request bodies so your server can reject forged events.

HMAC does not encrypt the payload. If the body contains sensitive data, you still need TLS and careful logging practices.

Implementation checklist

Agree on encoding, canonical payload bytes, and output format (hex or base64). Sign exactly the bytes the provider documents—sometimes a timestamp prefix is included.

Compare digests with a constant-time comparison in production code. Reject stale timestamps to reduce replay risk when the provider includes one.

Forgebox HMAC Generator can help create expected values for local tests while you build the server-side verifier, especially when you are aligning hex vs base64 output.

Operational tips

Store webhook secrets in a secret manager, rotate them when staff changes, and keep raw request bodies available until verification completes. Parsing JSON before signing often breaks canonical bytes.

Log verification failures with enough context to debug, but never log the shared secret or full sensitive payloads.