Slack Bot / Webhook Token Regex for JavaScript
/^(xoxb|xoxp|xoxa|xoxr|xoxs|xapp)-[A-Za-z0-9\-]{10,200}$|^https://hooks\.slack\.com/services/T[A-Z0-9]+/B[A-Z0-9]+/[A-Za-z0-9]+$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching slack bot / webhook token, ported and verified for JavaScript. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// Slack Bot / Webhook Token
// ReDoS-safe | RegexVault — Security > API Keys & Tokens
const slackBotWebhookTokenRegex = /^(xoxb|xoxp|xoxa|xoxr|xoxs|xapp)-[A-Za-z0-9\-]{10,200}$|^https:\/\/hooks\.slack\.com\/services\/T[A-Z0-9]+\/B[A-Z0-9]+\/[A-Za-z0-9]+$/;
function validateSlackBotWebhookToken(input: string): boolean {
return slackBotWebhookTokenRegex.test(input);
}
// Example
console.log(validateSlackBotWebhookToken("xoxb-123456789012-123456789012-ABC123def456GHI789jkl0")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
xoxb-123456789012-123456789012-ABC123def456GHI789jkl0 | xox-invalid-format |
xoxp-1234-5678-9012-abcdef1234567890abcdef | slack_token_aBcDeFgHiJkLmNoPqRsTuV |
https://hooks.slack.com/services/T12345/B12345/AbCdEfGhIj | xoxb-short |
When to use this pattern
This pattern is drawn from the Security > API Keys & Tokens category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
Bot tokens (xoxb) can access all channels the bot is in. User tokens (xoxp) act as that specific user. A leaked user token is equivalent to that user's password for Slack.
Technical Notes
Token prefixes: xoxb=bot token, xoxp=user token, xoxa=app-level token (legacy), xoxr=refresh token, xoxs=workspace token (legacy), xapp=Socket Mode app token. Webhook URLs are for incoming webhooks only and cannot read messages.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern