How to verify Slack request signatures (X-Slack-Signature) in Node.js
By David Garcia Berenguer · Published 2026-11-29 · Updated 2026-11-29 · Markdown version
Short answer: reject requests whose X-Slack-Request-Timestamp is more than five minutes from your clock, compute v0= + hex(HMAC-SHA256(signing secret, v0:<timestamp>:<raw body>)), and compare it with X-Slack-Signature in constant time. For the Events API, answer within three seconds and deduplicate on event_id.
What Slack sends
| Header or field | Meaning |
|---|---|
X-Slack-Signature |
v0= + hex HMAC-SHA256 of v0:<timestamp>:<raw body>, keyed with the app's signing secret |
X-Slack-Request-Timestamp |
Unix seconds; part of the signed string, so it can't be changed |
x-slack-retry-num, x-slack-retry-reason |
On retries only: attempt 1 to 3, and why (http_timeout, …) |
event_id (JSON body) |
Unique per event; the key for skipping duplicates |
type (JSON body) |
event_callback for events, url_verification when you set the Request URL |
Verifying in a Next.js route handler
// app/api/slack/events/route.ts
import { createHmac, timingSafeEqual } from "node:crypto";
export const runtime = "nodejs";
export async function POST(request: Request) {
const raw = await request.text(); // hash the exact bytes (slash commands send form data, signed the same way)
const ts = request.headers.get("x-slack-request-timestamp") ?? "";
if (!/^\d+$/.test(ts) || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return new Response("stale", { status: 401 });
const header = request.headers.get("x-slack-signature") ?? "";
const expected = "v0=" + createHmac("sha256", process.env.SLACK_SIGNING_SECRET!).update(`v0:${ts}:${raw}`).digest("hex");
const a = Buffer.from(header), b = Buffer.from(expected); // timingSafeEqual throws on different lengths
if (a.length !== b.length || !timingSafeEqual(a, b)) return new Response("invalid signature", { status: 401 });
const body = JSON.parse(raw);
if (body.type === "url_verification") return Response.json({ challenge: body.challenge });
// store body.event_id with a unique constraint, answer now, process afterwards
return new Response(null, { status: 200 });
}
Why verification fails
- The body was parsed first. Slash commands and interactive components arrive form-encoded, events as JSON. Either way, a parser that rebuilds the body changes the bytes.
- The wrong secret. It is the Signing Secret under Basic Information, not the deprecated verification token in the payload, nor a bot token.
- The timestamp. More than five minutes from your clock means a replay or a wrong clock. Check NTP on the server.
Paste a request into the webhook signature debugger (choose Slack) to see which of these it is. It runs in your browser.
Three seconds, three retries
Slack expects a 2xx within three seconds. Otherwise the attempt fails and Slack retries three times with exponential backoff, adding x-slack-retry-num and x-slack-retry-reason. Retries also count towards Slack's failure limits, so a slow endpoint can get its events disabled.
So verify, store the event, answer, then process. Keep event_id unique in your table and a retry of an event you already have costs nothing. Don't drop every request that has x-slack-retry-num: if the first attempt failed before you stored it, the retry is your only copy.
With Reliable Webhooks
Reliable Webhooks verifies Slack through its generic HMAC provider (with the timestamp check), stores events, skips duplicates by event_id and retries your handler. The url_verification handshake has no event_id, so answer it before the receiver:
import { Pool } from "pg";
import { createWebhookReceiver, hmacProvider, PostgresStore } from "@softreuse/webhook-kit";
const slack = createWebhookReceiver({
provider: hmacProvider({
name: "slack",
secret: process.env.SLACK_SIGNING_SECRET!,
signatureHeader: "x-slack-signature",
signaturePrefix: "v0=",
encoding: "hex",
timestampHeader: "x-slack-request-timestamp",
toleranceSeconds: 300,
signedMessage: (rawBody, ts) => `v0:${ts}:${rawBody}`,
identify: ({ rawBody }) => {
const body = JSON.parse(rawBody);
return { id: body.event_id, type: body.event?.type ?? body.type };
},
}),
store: new PostgresStore(new Pool({ connectionString: process.env.DATABASE_URL })),
handlers: {
app_mention: async ({ event, idempotencyKey }) => { /* reply once per idempotencyKey */ },
"*": () => {},
},
});
// app/api/slack/events/route.ts
export async function POST(request: Request) {
const raw = await request.text();
// Echoing the challenge reveals nothing, so it can be answered before verification.
const body = JSON.parse(raw);
if (body.type === "url_verification") return Response.json({ challenge: body.challenge });
return slack.handle(new Request(request.url, { method: "POST", headers: request.headers, body: raw }));
}
Sources
Frequently asked questions
How does Slack sign requests?
Slack builds the base string v0:<X-Slack-Request-Timestamp>:<raw body>, computes HMAC-SHA256 of it with your app's signing secret, and sends v0=<hex> in X-Slack-Signature. Events API callbacks, slash commands and interactivity requests are all signed this way.
Why does my Slack signature verification fail?
Usually the body was parsed first: slash commands and interactivity are form-encoded and Events API callbacks are JSON, and either way you must hash the exact bytes. Other causes are using the deprecated verification token instead of the signing secret, or a timestamp more than five minutes from your clock.
Why does Slack send the same event several times?
Slack expects a 2xx within three seconds. If it doesn't get one, it retries up to three times with backoff, adding x-slack-retry-num and x-slack-retry-reason. Deduplicate on the event_id in the payload and answer before doing slow work.
How do I answer Slack's url_verification challenge?
When you set the Request URL, Slack sends a request with type url_verification and a challenge value. Respond 200 with the challenge, as plain text or as JSON {"challenge": "..."}.
Free tools
- Webhook signature debugger: Find out why a Stripe, GitHub, Shopify, Slack or Standard Webhooks signature fails: paste the secret, header and raw body. Runs in your browser.