Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(switchdash): redact the credential key names configs actually use (CHOO-1784)

Louis Amaudruz9b328181c5f9
diff --git a/dash/apps/switchdash-desktop/src/main/core/switch-servers/create-bridge.test.ts b/dash/apps/switchdash-desktop/src/main/core/switch-servers/create-bridge.test.ts
index 861a8caf8..01be5e104 100644
--- a/dash/apps/switchdash-desktop/src/main/core/switch-servers/create-bridge.test.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/switch-servers/create-bridge.test.ts
@@ -83,7 +83,7 @@ describe('createBridgeOnServer', () => {
});
});
- it('sends the credentials in the gateway\'s snake_case shape', async () => {
+ it("sends the credentials in the gateway's snake_case shape", async () => {
fetchMock.mockResolvedValue(response(200, CREATED));
await createBridgeOnServer(SERVER, { ...PARAMS, setAsDefault: true });
diff --git a/dash/apps/switchdash-desktop/src/main/lib/file-logger.test.ts b/dash/apps/switchdash-desktop/src/main/lib/file-logger.test.ts
index bdf5e71bf..525c99c8c 100644
--- a/dash/apps/switchdash-desktop/src/main/lib/file-logger.test.ts
+++ b/dash/apps/switchdash-desktop/src/main/lib/file-logger.test.ts
@@ -15,6 +15,17 @@ vi.mock('electron', () => ({
},
}));
+/**
+ * A Discord-bot-token-shaped fixture, assembled at runtime.
+ *
+ * Written as a literal it trips GitHub's push protection, which classifies the
+ * shape as a Discord Bot Token regardless of the bytes being invented — fair
+ * evidence that the rule under test is aimed at the right thing, but not a
+ * reason to make the repo unpushable.
+ */
+const DISCORD_TOKEN_TAIL = 'abcdefghijklmnopqrstuvwxyz1';
+const DISCORD_TOKEN_SHAPE = ['MTA5NjE4NzQ5NDI4Nzk0MjA5', 'GhIjKl', DISCORD_TOKEN_TAIL].join('.');
+
describe('redactDiagnosticLog', () => {
it('redacts common secrets in free-form text', () => {
const redacted = redactDiagnosticLog(
@@ -84,6 +95,55 @@ describe('redactDiagnosticLog', () => {
expect(redacted).toContain('[REDACTED_NPM_TOKEN]');
});
+ it('redacts credentials under qualified key names, not just bare ones', () => {
+ // Real config keys are qualified. A bare word boundary before `token` does
+ // not match `bot_token`, so these are exactly the spellings that used to
+ // slip through — and exactly the ones a bridge config uses (CHOO-1784).
+ const redacted = redactDiagnosticLog(
+ [
+ `bot_token=${DISCORD_TOKEN_SHAPE}`,
+ '{"app_token":"xapp-1-A0123-456-secretvalue"}',
+ 'admin_password: hunter2',
+ '{"encryption_private_key":"MIIEpAIBAAKCAQEA"}',
+ 'client-secret = shhhhhhhh',
+ ].join('\n')
+ );
+
+ expect(redacted).not.toContain('hunter2');
+ expect(redacted).not.toContain('shhhhhhhh');
+ expect(redacted).not.toContain('MIIEpAIBAAKCAQEA');
+ expect(redacted).not.toContain('secretvalue');
+ expect(redacted).not.toContain(DISCORD_TOKEN_TAIL);
+ });
+
+ it('redacts a Slack app token and a Discord bot token', () => {
+ const redacted = redactDiagnosticLog(
+ ['xapp-1-A012BCDEFGH-1234567890123-abcdef', DISCORD_TOKEN_SHAPE].join('\n')
+ );
+
+ expect(redacted).toContain('[REDACTED_SLACK_TOKEN]');
+ expect(redacted).toContain('[REDACTED_DISCORD_TOKEN]');
+ });
+
+ it('redacts the token after a Bot auth scheme, not just Bearer', () => {
+ // `Authorization: Bot <token>` is Discord's canonical header. Redacting the
+ // scheme word and leaving the token behind is worse than useless.
+ const redacted = redactDiagnosticLog('Authorization: Bot abcdefghijklmnop');
+
+ expect(redacted).not.toContain('abcdefghijklmnop');
+ });
+
+ it('leaves non-secret keys alone', () => {
+ // The qualifier prefix must not turn every underscored key into a secret.
+ const redacted = redactDiagnosticLog(
+ ['workspace_id=T0123456', 'room_name: design-review', 'agent_id=agent-7'].join('\n')
+ );
+
+ expect(redacted).toContain('T0123456');
+ expect(redacted).toContain('design-review');
+ expect(redacted).toContain('agent-7');
+ });
+
it('redacts PEM private-key blocks', () => {
const pem = [
'-----BEGIN RSA PRIVATE KEY-----',
diff --git a/dash/apps/switchdash-desktop/src/main/lib/file-logger.ts b/dash/apps/switchdash-desktop/src/main/lib/file-logger.ts
index d734073f1..2804a3f3d 100644
--- a/dash/apps/switchdash-desktop/src/main/lib/file-logger.ts
+++ b/dash/apps/switchdash-desktop/src/main/lib/file-logger.ts
@@ -22,8 +22,20 @@ const FLUSH_INTERVAL_MS = 250;
const FLUSH_BYTES = 64 * 1024;
const DIAGNOSTIC_SECTION_TIMEOUT_MS = 5000;
-const SECRET_KEY_NAMES =
- 'authorization|api[_-]?key|token|password|passphrase|secret|access[_-]?token|refresh[_-]?token|client[_-]?secret';
+/** The words that mark a value as a credential. */
+const SECRET_KEY_WORDS =
+ 'authorization|api[_-]?key|private[_-]?key|token|password|passphrase|secret|credential';
+
+/**
+ * A credential-bearing key name, with any number of leading qualifier segments.
+ *
+ * The qualifier prefix is load-bearing, not decoration: a bare `\b` before
+ * `token` does not match `bot_token`, because `_` is a word character and there
+ * is no boundary inside it. Real config keys are almost always qualified —
+ * `bot_token`, `app_token`, `admin_password`, `client_secret` — so without this
+ * the alternation only caught the unqualified spelling nobody uses.
+ */
+const SECRET_KEY_NAMES = `(?:[a-z0-9]+[_-])*(?:${SECRET_KEY_WORDS})`;
type RedactionReplacement = string | ((substring: string, ...args: string[]) => string);
@@ -34,9 +46,14 @@ const SECRET_PATTERNS: Array<[RegExp, RedactionReplacement]> = [
(_match, openQuote: string, keyName: string, closeQuote: string, separator: string) =>
`${openQuote}${keyName}${closeQuote}${separator}${openQuote}[REDACTED]${openQuote}`,
],
- // Unquoted: key=value or key: bearer value
+ // Unquoted: key=value, or key: <scheme> value. The scheme alternation must
+ // stay in step with the auth schemes we might log: without `bot`, Discord's
+ // `Authorization: Bot <token>` redacts the word "Bot" and leaves the token.
[
- new RegExp(`\\b(${SECRET_KEY_NAMES})(\\s*[:=]\\s*)(?:bearer\\s+)?[^\\s,"'}]+`, 'gi'),
+ new RegExp(
+ `\\b(${SECRET_KEY_NAMES})(\\s*[:=]\\s*)(?:(?:bearer|bot|token)\\s+)?[^\\s,"'}]+`,
+ 'gi'
+ ),
'$1$2[REDACTED]',
],
// PEM blocks (private keys)
@@ -49,8 +66,14 @@ const SECRET_PATTERNS: Array<[RegExp, RedactionReplacement]> = [
[/\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{20,}\b/g, '[REDACTED_STRIPE_KEY]'],
[/\bsk-ant-[A-Za-z0-9_-]{20,}\b/g, '[REDACTED_ANTHROPIC_KEY]'],
[/\bsk-[A-Za-z0-9_-]{20,}\b/g, '[REDACTED_OPENAI_KEY]'],
- [/\bxox[baprs]-[A-Za-z0-9-]{20,}\b/g, '[REDACTED_SLACK_TOKEN]'],
+ // `xoxe` is a rotating/refresh token; `xapp` is an app-level token, which a
+ // Slack bridge needs alongside the bot token for Socket Mode.
+ [/\b(?:xox[abepprs]|xapp)-[A-Za-z0-9-]{15,}\b/g, '[REDACTED_SLACK_TOKEN]'],
[/\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, '[REDACTED_JWT]'],
+ // Discord bot token: base64 client id . 6-char timestamp . hmac. Unprefixed,
+ // so it is matched structurally. Kept after the JWT rule, whose middle
+ // segment is far longer than six characters, so the two cannot collide.
+ [/\b[A-Za-z0-9_-]{23,28}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{27,}\b/g, '[REDACTED_DISCORD_TOKEN]'],
];
const PII_PATTERNS: Array<[RegExp, RedactionReplacement]> = [