Slack Bot / Webhook Token Regex for Go
/^(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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// Slack Bot / Webhook Token
// ReDoS-safe | RegexVault — Security > API Keys & Tokens
package validation
import "regexp"
var slackBotWebhookTokenRe = regexp.MustCompile(`^(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]+$`)
func ValidateSlackBotWebhookToken(s string) bool {
return slackBotWebhookTokenRe.MatchString(s)
}
// Example
// fmt.Println(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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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