Skip to content

Verify HMAC webhook signatures and block spoofed requests

Validate cryptographic signatures, replay timestamps, and IP allowlists at pipeline ingress before any untrusted payload triggers internal tools.

Copy the prompt and paste it into the AI assistant you already use.

Security checklist for public webhook endpoints

  1. 01

    Compute digests against the exact raw bytes

    Hash the unparsed UTF-8 request body before JSON formatting changes whitespace or key ordering.

  2. 02

    Compare signatures in constant time

    Use timing-safe byte comparisons to prevent side-channel attacks against public webhook URLs.

  3. 03

    Enforce strict timestamp freshness windows

    Include the header timestamp in the signed payload check and reject requests older than 300 seconds.

  4. 04

    Support dual signing secrets during rotation

    Allow overlapping active and next secrets so security teams can rotate webhook keys with zero dropped events.

Common questions

Why does HMAC verification fail when middleware parses JSON first?

Re-serializing parsed JSON alters whitespace or key order, changing the SHA-256 digest; signatures must always be checked on raw bytes.

How do dual signing secrets prevent downtime during security rotations?

The verifier checks the primary secret first and falls back to the secondary secret until the upstream vendor finishes switching keys.

Should rejected invalid-signature requests trigger security notifications?

Yes, repeated signature failures from unknown IPs log metadata to an anomaly alert without executing any downstream business tools.

Learn more

Related guides and background articles for this task