Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(redact): mask Slack app-level tokens (xapp-) (#4065)

kevin0fdb32dfba94
diff --git a/server/redact.test.ts b/server/redact.test.ts
index c40e89d569..ede14c2868 100644
--- a/server/redact.test.ts
+++ b/server/redact.test.ts
@@ -142,6 +142,7 @@ describe("redactSecretsInText", () => {
[`gh token ${"gh" + "p_"}${alpha}`, /ghp_/],
[`fine-grained ${"github_" + "pat_"}11ABCDEFG0${alpha}`, /github_pat_/],
[`slack ${"xox" + "b-"}${"123456789012"}-${"1234567890123"}-${alpha.slice(0, 24)}`, /xoxb-/],
+ [`slack app ${"xa" + "pp-"}1-A0123456789-${"1234567890123"}-${alpha.slice(0, 24)}`, /xapp-|A0123456789/],
[`aws ${"AKIA" + "IOSFODNN7EXAMPLE"} and more`, /IOSFODNN7EXAMPLE/],
[`google ${"AIza" + "SyA-"}${alpha.slice(0, 32)}`, /AIza/],
[`npm ${"npm" + "_"}${alpha}`, /npm_[a-z]/],
@@ -290,7 +291,7 @@ describe("holdsCredential", () => {
it("knows a provider key or a private key block, never a name, a placeholder or code that reads one", () => {
for (const text of [
'{"apiKey": "sk-ant-api03-0123456789abcdefABCD"}', "GITHUB_TOKEN=ghp_0123456789abcdefghij0123", "-----BEGIN OPENSSH PRIVATE KEY-----\nabc\n",
- "aws_access_key_id = AKIAABCDEFGHIJKLMNOP", `git clone https://oauth2:${"glp" + "at-"}[email protected]/x.git`, `runner token ${"glr" + "tr-"}0123456789abcdefABCD`, `stripe.secret = "${"sk_" + "live_"}0123456789abcdefABCD"`,
+ "aws_access_key_id = AKIAABCDEFGHIJKLMNOP", `git clone https://oauth2:${"glp" + "at-"}[email protected]/x.git`, `runner token ${"glr" + "tr-"}0123456789abcdefABCD`, `SLACK_APP_TOKEN: ${"xa" + "pp-"}1-A0123456789-1234567890123-abcdef0123456789`, `stripe.secret = "${"sk_" + "live_"}0123456789abcdefABCD"`,
]) expect(holdsCredential(text), text).toBe(true);
for (const text of [
"token = os.environ['GITHUB_TOKEN']", "API_KEY=your-key-here", "Authorization: Bearer YOUR_TOKEN_HERE", "Keep credentials out of the repo.",
diff --git a/shared/redact.ts b/shared/redact.ts
index dc3be7ef51..2b90e8c0fb 100644
--- a/shared/redact.ts
+++ b/shared/redact.ts
@@ -26,6 +26,7 @@ const KEY_PREFIXES: RegExp[] = [
/\bgithub_pat_[A-Za-z0-9_]{20,}/g, // github fine-grained
/\bgl(?:pat|dt|rtr?)-[A-Za-z0-9_-]{20,}(?:\.[A-Za-z0-9_-]+)*/g, // gitlab personal, deploy and runner tokens (routable ones carry .-parts)
/\bxox[abposr]-[A-Za-z0-9-]{20,}/g, // slack
+ /\bxapp-\d-[A-Za-z0-9-]{20,}/g, // slack app-level (socket mode) tokens
/\bAKIA[0-9A-Z]{16}\b/g, // aws access key id
/\bAIza[0-9A-Za-z_-]{30,}/g, // google api key
/\bnpm_[A-Za-z0-9]{20,}/g, // npm