Surge-Signature header
Each webhook Surge delivers includes a “Surge-Signature” header that looks like this:t: Unix timestamp indicating when webhook was sentv1: Lowercase hex-encoded HMAC-SHA256 signature- We may send more than one
v1hash when rolling credentials
- We may send more than one
, or =, so these can be split upon to parse the header.
Validation Steps
- Check timestamp: Verify timestamp is within an acceptable time window (such as 5 minutes) to prevent replay attacks.
-
Generate payload: The payload signed to create the header is a concatenation of 3 things:
- Timestamp from step 1
- Period (
.) - Raw webhook body
-
Compute expected hash: Generate HMAC-SHA256 hash for the payload from step 2.
- Use the signing secret you received when setting up your webhook endpoint.
-
Compare hashes: Check computed hash from step 3 with
v1from header.- Use constant-time string comparison to protect against timing attacks.
- There may be multiple
v1parameters in the header- Only compare to
v1, not other versions which may be added in the future - If any of the
v1hashes match, the signature should be accepted as authentic
- Only compare to