Twilio Auth Token / SID Regex for Go
/^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$/iWhat this pattern does
This page provides a well-structured, multi-part regular expression for matching twilio auth token / sid, 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
// Twilio Auth Token / SID
// ReDoS-safe | RegexVault — Security > API Keys & Tokens
package validation
import "regexp"
var twilioAuthTokenSidRe = regexp.MustCompile(`^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$`)
func ValidateTwilioAuthTokenSid(s string) bool {
return twilioAuthTokenSidRe.MatchString(s)
}
// Example
// fmt.Println(ValidateTwilioAuthTokenSid("ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 | AC_short |
SKa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 | BCa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 |
a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 | ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4X |
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
Twilio Auth Tokens are the master credential — prefer API Keys with limited scope. A leaked Auth Token allows sending bulk SMS from your account, triggering massive charges and potential spam reports.
Technical Notes
Twilio Account SID: AC + 32 hex chars. Auth Token: 32 hex chars (no prefix). API Key SID: SK + 32 hex chars. Auth Tokens have full account access. API Keys can be scoped and are preferred over Auth Tokens.
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