Slack Events API: URL verification, signatures and retries
Your Request URL check fails, your signature check rejects requests, or the same event arrives repeatedly. Check the challenge reply first, then the signing inputs, then the response time and duplicate handling.
Bolt 5.1.0 reports a signature mismatch as Failed to verify authenticity: signature mismatch.
That error means its computed HMAC did not match the received signature. It does not identify which input changed.
1. Return the challenge after verifying the request
Section titled “1. Return the challenge after verifying the request”When you configure an Events API Request URL, Slack sends a url_verification event.
Its top-level fields are type, challenge and the deprecated token; it has no inner event.
Verify the request’s signature first. Ignore the old token when authenticating it.
Slack documents three accepted responses, each with 200 OK:
| Content type | Response body for a test challenge test-challenge |
|---|---|
text/plain |
test-challenge |
application/x-www-form-urlencoded |
challenge=test-challenge |
application/json |
{"challenge":"test-challenge"} |
Return the received challenge value, not the entire request payload or an unrelated success message.
The Express sample below uses plain text. It returns 401 without the challenge when verification fails.
2. Keep the signing inputs unchanged
Section titled “2. Keep the signing inputs unchanged”Slack sends X-Slack-Signature and X-Slack-Request-Timestamp. Header names are case-insensitive.
The signing base is v0:<timestamp>:<raw body>.
Compute HMAC-SHA256 using the signing secret as a UTF-8 string, encode the digest as hex, and prefix it with v0=.
Compare the result in constant time.
Check these inputs in order:
- Read the raw body before parsing. The Events API sends JSON; slash commands and interactivity use form-encoded bodies.
- Keep the original bytes. Re-serializing JSON or changing form encoding changes the signature input.
- Use your app’s Signing Secret from Basic Info. Do not hex-decode it or substitute the deprecated verification token.
- Preserve both signature headers through your proxy. Treat a missing or malformed header as a rejection.
- Verify when the request arrives. Slack’s documentation checks that the timestamp differs from local time by no more than five minutes.
Correct a drifting server clock instead of removing the age check. For one test request, compare body length and SHA-256 before and after a suspected proxy or body parser. Compare the same request at both points; unrelated deliveries cannot prove a byte change.
The verifiers below accept a timestamp exactly 300 seconds away and reject one 301 seconds away, in either direction.
Bolt 5.1.0 checks only past age; these samples also reject timestamps too far in the future, following Slack’s documentation.
Slack documents a lowercase digest and v0= prefix; case normalization is undocumented.
These samples follow Bolt 5.1.0’s strict case-sensitive comparison.
These samples reject uppercase or mixed-case digests and V0=; Bolt 5.1.0 also rejects them.
They reject empty secrets, including a correctly computed signature made with an empty key.
3. Accept durably within three seconds
Section titled “3. Accept durably within three seconds”Slack requires an HTTP 2xx response within three seconds.
Verify, store or enqueue durably, answer, then process in a separate worker.
A failed write must return a retriable failure; the sample uses 500.
Never answer success before the queue confirms durable acceptance.
Slack retries a failed request up to three times:
| Retry | When |
|---|---|
| 1 | Nearly immediately |
| 2 | After 1 minute |
| 3 | After 5 minutes |
Each retry carries x-slack-retry-num (1, 2 or 3) and x-slack-retry-reason:
| Reason | Meaning | Check |
|---|---|---|
http_timeout |
Previous response took longer than 3 seconds | Move slow processing to a worker |
too_many_redirects |
More than 2 redirects | Configure the final Request URL |
connection_failed |
DNS or host connection failed | Check DNS and reachability |
ssl_error |
Certificate verification failed | Check the certificate and chain |
http_error |
Response was outside the HTTP 200 OK range | Check application and proxy status logs |
unknown_error |
Slack could not identify the failure | Correlate request and infrastructure logs |
Retries count toward failure limits. Slack temporarily disables subscriptions when more than 95% of delivery attempts fail within 60 minutes. The listed failures are certificate negotiation or validation, a response taking longer than three seconds, more than two redirects, and responses outside the HTTP 200-series except allowed redirects. Apps receiving fewer than 1,000 events per hour are exempt from automatic disabling. After repairing the endpoint, re-enable subscriptions in app management; Marketplace apps use Live App Settings.
A non-success response can include x-slack-no-retry: 1 to stop retries for that specific event.
Do not send this header for a temporary queue failure: doing so asks Slack to stop that event’s recovery attempts.
Under Event Subscriptions, Delayed Events adds hourly retries for 24 hours after the normal three retries. Without it, Slack does not attempt delivery of events more than two hours late; enabling it permits those delayed deliveries. The Events API remains a best-effort system. Keep deduplication when enabling delayed delivery or restoring subscriptions.
4. Deduplicate by event_id
Section titled “4. Deduplicate by event_id”The Events API envelope’s event_id identifies an event and is globally unique across workspaces.
Use it as the durable duplicate key. Retry headers explain the delivery attempt; they do not replace the event ID.
A late or lost response does not prove that processing failed. A retry can arrive after your original request succeeded.
Make duplicate detection and job creation one atomic operation, such as a unique event ID plus a transactional outbox. Do not record an ID as accepted before the event is durable. A worker should also make business effects idempotent across job retries. Keep an already accepted duplicate as a successful no-op.
Tested samples
Section titled “Tested samples”These verifiers take raw bytes and an injected Unix-seconds clock. The fixtures include Slack’s documented example,
a JSON event, slash-command and interactivity form bodies, altered bytes, wrong and empty secrets, malformed headers, and both timestamp boundaries.
For interactivity, verification covers the whole form body, including payload=<URL-encoded JSON>, before decoding.
The fixtures reject a decoded-and-reserialized payload sent with the original signature.
Node verifier
Section titled “Node verifier”import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifySlack(rawBody, signature, timestamp, secret, now) { // An empty key would let anyone forge a signature. if (typeof secret !== 'string' || secret.length === 0) return 'invalid'; if (signature == null || signature === '' || timestamp == null || timestamp === '') return 'missing'; if (typeof signature !== 'string' || !/^v0=[0-9a-f]{64}$/.test(signature)) return 'invalid'; if (typeof timestamp !== 'string' || !/^[0-9]{1,15}$/.test(timestamp)) return 'invalid'; if (!Number.isSafeInteger(now)) return 'invalid'; if (Math.abs(now - Number(timestamp)) > 300) return 'expired'; const expected = createHmac('sha256', Buffer.from(secret, 'utf8')) .update(`v0:${timestamp}:`, 'utf8').update(rawBody).digest(); const given = Buffer.from(signature.slice(3), 'hex'); return timingSafeEqual(given, expected) ? 'valid' : 'invalid';}Express Events API route
Section titled “Express Events API route”Supply secret from secure configuration and now: () => Math.floor(Date.now() / 1000).
Supply a durable queue.enqueueOnce(eventId, event) implementation: it must commit before resolving,
atomically ignore accepted IDs, and reject failed writes. An in-memory collection does not meet that contract.
Run a separate queue worker to process committed jobs after acceptance, with idempotent business effects.
The HTTP handler itself does no business processing.
import express from 'express';import { verifySlack } from './verify-slack.mjs';
export function slackEventsApp({ secret, now, queue }) { const app = express(); // Keep this route before global JSON parsing. Do not inflate signed bytes. app.post('/slack/events', express.raw({ type: 'application/json', inflate: false, limit: '1mb' }), async (req, res) => { if (!Buffer.isBuffer(req.body)) return res.status(415).send('Unsupported content type'); const verdict = verifySlack(req.body, req.get('X-Slack-Signature'), req.get('X-Slack-Request-Timestamp'), secret, now()); if (verdict !== 'valid') return res.status(401).send('Invalid request'); let event; try { event = JSON.parse(req.body.toString('utf8')); } catch { return res.status(400).send('Invalid JSON'); } if (event?.type === 'url_verification') { if (typeof event.challenge !== 'string') return res.status(400).send('Invalid challenge'); return res.status(200).type('text/plain').send(event.challenge); } if (event?.type !== 'event_callback' || typeof event.event_id !== 'string' || !event.event_id) { return res.status(400).send('Invalid event'); } try { // Resolves only after durable acceptance; duplicate IDs are an atomic no-op. await queue.enqueueOnce(event.event_id, event); } catch { return res.status(500).send('Queue unavailable'); } return res.status(200).end(); }); app.use(express.json()); return app;}The test adapter injects a fake queue and makes loopback HTTP requests.
It checks successful enqueue, signed challenge, rejected challenge, failed enqueue, duplicate acceptance, malformed JSON and unsupported content types.
The ordering test proves enqueue completes before success; an enqueue error returns 500.
The handler contains no business processing code.
This proves handler ordering and responses, not the durability of a production queue.
Python verifier
Section titled “Python verifier”import hashlibimport hmacimport re
def verify_slack(raw_body, signature, timestamp, secret, now): if not isinstance(secret, str) or not secret: return "invalid" if signature is None or signature == "" or timestamp is None or timestamp == "": return "missing" if not isinstance(signature, str) or not re.fullmatch(r"v0=[0-9a-f]{64}", signature): return "invalid" if not isinstance(timestamp, str) or not re.fullmatch(r"[0-9]{1,15}", timestamp): return "invalid" if abs(now - int(timestamp)) > 300: return "expired" base = ("v0:" + timestamp + ":").encode("utf-8") + raw_body expected = "v0=" + hmac.new(secret.encode("utf-8"), base, hashlib.sha256).hexdigest() return "valid" if hmac.compare_digest(signature, expected) else "invalid"Go verifier
Section titled “Go verifier”Import crypto/hmac, crypto/sha256, encoding/hex, strconv and strings in your Go package. Pass the unparsed request body and an injected Unix-seconds clock.
func verifySlack(body []byte, signature, timestamp, secret string, now int64) string { if secret == "" { return "invalid" } if signature == "" || timestamp == "" { return "missing" } if len(signature) != 67 || !strings.HasPrefix(signature, "v0=") { return "invalid" } if strings.Trim(signature[3:], "0123456789abcdef") != "" { return "invalid" } if len(timestamp) > 15 || strings.Trim(timestamp, "0123456789") != "" { return "invalid" } ts, err := strconv.ParseInt(timestamp, 10, 64) if err != nil { return "invalid" } if ts < now-300 || ts > now+300 { return "expired" } given, err := hex.DecodeString(signature[3:]) if err != nil { return "invalid" } mac := hmac.New(sha256.New, []byte(secret)) _, _ = mac.Write([]byte("v0:" + timestamp + ":")) _, _ = mac.Write(body) if !hmac.Equal(given, mac.Sum(nil)) { return "invalid" } return "valid"}Checklist
Section titled “Checklist”- Verify the signature before answering
url_verification; return its challenge in an accepted response form. - Hash the original body bytes with the Signing Secret as UTF-8 text.
- Preserve both Slack headers and keep the server clock correct.
- Commit the event before
200; return500if enqueue fails. - Process from a separate worker and deduplicate by
event_id. - Check retry reasons, subscription status and the Delayed Events setting before recovery.
Sources
Section titled “Sources”Checked on 2026-11-08.
- Slack: Verifying requests from Slack: “Understanding signed secrets” and “Validating a request” (headers, UTF-8 secret, raw body, HMAC, timestamp window, worked example).
- Slack: url_verification: “Usage info” (payload, authenticity check, three response forms, deprecated token).
- Slack: Events API: “Events dispatched as JSON”, “Callback field overview”, “Responding to events”, “Retries”, “Failure limits”, “Turning retries off”, “Resuming event deliveries” and “Delayed events retry”.
- Slack: Implementing slash commands: “Command payload info” (form encoding).
- Slack: Handling user interaction: “Handling interaction payloads” (form encoding).
@slack/bolt5.1.0:src/receivers/verify-request.ts, lines 9, 26–68:verifySlackRequest, error prefix and mismatch text, past-age check and HMAC algorithm.