Skip to content

Commit 80bd9b5

Browse files
committed
fix(slack): harden cookie decryption and remove dead WorkspaceURL field
- Validate ciphertext is block-aligned to prevent CryptBlocks panic - Error on unrecognized encryption version prefix (not just v10) - Return error when decrypted output has no xoxd- token - Remove unused WorkspaceURL field from Credentials
1 parent da48bcd commit 80bd9b5

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

source/slack/desktop/cookies.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,19 @@ func decryptCookie(encrypted, key []byte) (string, error) {
9898
if len(encrypted) < 3 {
9999
return "", fmt.Errorf("encrypted value too short")
100100
}
101-
if string(encrypted[:3]) == "v10" {
102-
encrypted = encrypted[3:]
101+
prefix := string(encrypted[:3])
102+
if prefix != "v10" {
103+
return "", fmt.Errorf("unsupported encryption version %q", prefix)
103104
}
105+
encrypted = encrypted[3:]
104106

105107
block, err := aes.NewCipher(key)
106108
if err != nil {
107109
return "", fmt.Errorf("create cipher: %w", err)
108110
}
109111

110-
if len(encrypted) < aes.BlockSize {
111-
return "", fmt.Errorf("ciphertext too short")
112+
if len(encrypted) < aes.BlockSize || len(encrypted)%aes.BlockSize != 0 {
113+
return "", fmt.Errorf("ciphertext length %d is not a multiple of block size", len(encrypted))
112114
}
113115

114116
// Chromium uses 16 bytes of space as IV.
@@ -135,7 +137,7 @@ func decryptCookie(encrypted, key []byte) (string, error) {
135137
return match, nil
136138
}
137139

138-
return string(plaintext), nil
140+
return "", fmt.Errorf("no xoxd- token found in decrypted cookie")
139141
}
140142

141143
func getKeychainPassword() (string, error) {

source/slack/desktop/extract.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import (
88
)
99

1010
type Credentials struct {
11-
Token string
12-
Cookie string
13-
TeamID string
14-
TeamName string
15-
WorkspaceURL string
11+
Token string
12+
Cookie string
13+
TeamID string
14+
TeamName string
1615
}
1716

1817
func Extract() (*Credentials, error) {

0 commit comments

Comments
 (0)