Webhook Signature

A webhook signature is a provider-computed HMAC over the raw HTTP request body that allows the backend to verify the sender and detect modifications to the content. The backend calculates the expected signature using the shared secret and compares it with the value in the X-Signature header using constant-time comparison before parsing the JSON.

Minimal example

go
mac := hmac.New(sha256.New, secret)
mac.Write(body)
expected := mac.Sum(nil)
provided, err := hex.DecodeString(signature)
if err != nil || !hmac.Equal(expected, provided) {
    return ErrInvalidSignature
}

Learn this concept

Lesson 8.3 · HMAC webhooks and payment sagas

Used in exercises

Exercise 8.4 · Payment processing service Exercise 8.13 · Timestamped webhook signature package
Prerequisite conceptsHMACConstant-time comparison