hooksig / Slack
HMAC-SHA256 · hex · timestamped
Slack
Its basestring format and the separate timestamp header are what everyone gets wrong.
Try it — live, in your browser
Request — edit anything
Verify this in code
import { verify } from "hooksig";
const result = await verify("slack", {
payload: rawBody, // the RAW body, not parsed JSON
headers: request.headers,
secret: env.WEBHOOK_SECRET,
});
if (!result.verified) {
return new Response(result.reason, { status: 400 });
}no match — signature invalid
Signed string
HMAC-SHA256( secret, signed string ) = expected
Expected vs provided
expected
provided
How it's built
The scheme
- Header
X-Slack-Signature - AlgorithmHMAC-SHA256
- Encodinghex
- Timestampyes, so it has replay protection
- SignsHMAC-SHA256 over `v0:{timestamp}:{body}`, hex, prefixed `v0=`. The timestamp arrives in its own header.
Gotchas
- The signed string is `v0:{timestamp}:{body}` with colons, and the timestamp comes from X-Slack-Request-Timestamp, a separate header.
- Prefix your computed digest with v0= before comparing.
- Reject requests whose timestamp is more than five minutes old to stop replays.
- Sign the raw body, before any URL-decoding of the form payload.