Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token patterns fix #398

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/slackdump/internal/man/assets/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Automated:
- Browser authentication (**_EZ-Login 3000_**);

Manual:
- Login with Client Token and a cookie value;
- Login with Client Token (`xoxc-`) and a cookie value;
- Login with Client Token and a Cookie file, exported from your browser;
- Login with Legacy `xoxp-`, Application `xoxa-` or Bot `xoxb-` Token
- Login with Legacy `xoxp-`, Application `xapp-` or Bot `xoxb-` Token
(no cookie needed).


Expand Down
2 changes: 1 addition & 1 deletion cmd/slackdump/internal/workspace/assets/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ current.

**SLACK_TOKEN** can be one of the following types:

- xoxa-...: App token
- xapp-...: App token
- xoxb-...: Bot token
- xoxc-...: Client token
- xoxe-...: Export token
Expand Down
4 changes: 2 additions & 2 deletions internal/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

const (
TestAppToken = "xoxa-888888888888-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
TestBotToken = "xoxb-888888888888-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
TestAppToken = "xapp-1-A012RNBPFL3-1234567890123-c045facebeefbabecafef624ab2f2fe1cc640babf30e37e6b2d11c6094774782"
TestBotToken = "xoxb-123456789012-1234567890123-qCl4vKrWXWjArO5eoWgEUIPb"
TestClientToken = "xoxc-888888888888-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
TestExportToken = "xoxe-888888888888-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
TestPersonalToken = "xoxp-777777777777-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
Expand Down
16 changes: 11 additions & 5 deletions internal/structures/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ const (

// tokenRe is a loose regular expression to match Slack API tokens.
// a - app, b - bot, c - client, e - export, p - legacy
var tokenRE = regexp.MustCompile(`xox[abcep]-[0-9]+-[0-9]+-[0-9]+-[0-9a-f]{64}`)
var (
tokenRE = regexp.MustCompile(`\bxox[abcep]-[0-9]+-[0-9]+-[0-9]+-[0-9a-fA-F]{64}\b`)
appTokenRE = regexp.MustCompile(`\bx(?:app|oxa)-(?:\d-)?(?:[a-zA-Z0-9]{1,20}-)+[a-fA-F0-9]{1,64}\b`)
botTokenRE = regexp.MustCompile(`\bxoxb-(?:[a-zA-Z0-9]{1,20}-){2}[a-zA-Z0-9]{1,40}\b`)
)

var errInvalidToken = errors.New("token must start with xoxa-, xoxb-, xoxc-, xoxe- or xoxp- and be followed by 3 group of numbers and then 64 hexadecimal characters")
var ErrInvalidToken = errors.New("token must start with xoxa-, xoxb-, xoxc-, xoxe- or xoxp- and be followed by 3 group of numbers and then 64 hexadecimal characters")

func ValidateToken(token string) error {
if !tokenRE.MatchString(token) {
return errInvalidToken
for _, pattern := range []*regexp.Regexp{appTokenRE, botTokenRE, tokenRE} {
if pattern.MatchString(token) {
return nil
}
}
return nil
return ErrInvalidToken
}

var ErrInvalidDomain = errors.New("invalid domain")
Expand Down
8 changes: 4 additions & 4 deletions internal/structures/structures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ func TestValidateToken(t *testing.T) {
},
{
name: "short token",
args: args{token: "xoxa-123456789012-123456789012-123456789012-1234567890123456789012345678901"},
args: args{token: "xoxc-123456789012-123456789012-123456789012-1234567890123456789012345678901"},
wantErr: true,
},
{
name: "long token",
args: args{token: "xoxa-123456789012-123456789012-123456789012-123456789012345678901234567890123"},
args: args{token: "xoxc-123456789012-123456789012-123456789012-123456789012345678901234567890123"},
wantErr: true,
},
{
name: "non-numeric sections",
args: args{token: "xoxa-123456789012-abcdefg-123456789012-12345678901234567890123456789012"},
args: args{token: "xoxc-123456789012-abcdefg-123456789012-12345678901234567890123456789012"},
wantErr: true,
},
{
name: "non-alphanumeric suffix",
args: args{token: "xoxa-123456789012-123456789012-123456789012-1234567890123456789012345678901!"},
args: args{token: "xoxc-123456789012-123456789012-123456789012-1234567890123456789012345678901!"},
wantErr: true,
},
}
Expand Down
2 changes: 1 addition & 1 deletion slackdump.1
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ avoid bot detection algorithms.
.Bl -tag -width token+cookie
.It Em token
This method requires Application
.Pq xoxa-
.Pq xapp-
, Bot
.Pq xoxb-
or a Legacy
Expand Down
Loading