Verify Webhook Authenticity Before Processing
Authenticate provider-specific raw bytes and timestamp contracts with safe key selection before parsing or applying effects.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
Authenticate the bytes before trusting the event
A webhook is an inbound message from another system. Its URL being obscure does not authenticate the sender. A signature or MAC can establish that a trusted key holder authenticated particular bytes under a signing contract. The receiver must implement that exact contract before parsing the event into business authority.
InvoicePost's teaching provider signs a decimal timestamp, a dot, and the exact raw request body using HMAC-SHA256. The signature is hex encoded. This is a fixture protocol, not a universal webhook format: real providers differ in header syntax, separators, key selection, algorithms, and retry behavior.
signed bytes = ASCII(timestamp) || "." || raw_request_body
signature = HMAC-SHA256(endpoint_secret, signed bytes)
Headers:
X-Event-Timestamp: 1794744000
X-Event-Signature: <64 hex characters>
The signature covers the timestamp because freshness depends on it. If an attacker can replace an unsigned timestamp beside an otherwise valid signature, a freshness check can be defeated without forging the body MAC.