Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companions): redact array-valued credentials
Chris7b74ae959e64
diff --git a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.tsindex e0ad2439c8..b6eae0b751 100644--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts@@ -247,10 +247,11 @@ it('masks argv-only credentials again before publishing legacy command results',it.each(['stdin', 'argv', 'assignment'] as const)('masks nested JSON credentials from %s in execution, cached output and publication', async source => {const routine = { id: 'routine', botId: 'bot', prompt: 'Fixture structured input' } as Routine;const secret = 'fixture-nested-"quoted"\n-secret';- const input = JSON.stringify({ credentials: [{ token: secret }], city: 'Paris', count: 7 });+ const arraySecret = 'fixture-array-secret';+ const input = JSON.stringify({ credentials: [{ token: secret, api_key: [arraySecret] }], city: 'Paris', cities: ['Paris', 'London'], count: 7 });const read = source === 'stdin' ? 'require("node:fs").readFileSync(0,"utf8")': source === 'assignment' ? 'process.argv[1].slice("--config=".length)' : 'process.argv[1]';- const code = `const input=JSON.parse(${read}); process.stdout.write(JSON.stringify({token:input.credentials[0].token,city:input.city,count:input.count}));`;+ const code = `const input=JSON.parse(${read}); process.stdout.write(JSON.stringify({token:input.credentials[0].token,arrayToken:input.credentials[0].api_key[0],city:input.city,cities:input.cities,count:input.count}));`;const original = { payload: { kind: 'command', argv: [process.execPath, '-e', code,...(source === 'stdin' ? [] : ['--', source === 'assignment' ? `--config=${input}` : input])],...(source === 'stdin' ? { input } : {}), cwd: root } };@@ -259,12 +260,12 @@ it.each(['stdin', 'argv', 'assignment'] as const)('masks nested JSON credentials} }, () => {});const signal = new AbortController().signal;const prepared = await prepareImportedAutomation(root, routine, 'structured-run', signal, () => {});- expect(JSON.parse(prepared!.direct!)).toEqual({ token: expect.stringMatching(/^\[command_literal_/), city: 'Paris', count: 7 });+ expect(JSON.parse(prepared!.direct!)).toEqual({ token: expect.stringMatching(/^\[command_literal_/), arrayToken: expect.stringMatching(/^\[command_literal_/), city: 'Paris', cities: ['Paris', 'London'], count: 7 });const saved = (await shared.store.read(root, 'bot', () => {}))!.automations!.routine!;expect(saved.original).toEqual(original);expect(saved.prepared?.direct).toBe(prepared!.direct);// Old private output must be masked even when no process is executed again.- const legacy = JSON.stringify({ token: secret, city: 'Paris', count: 7 });+ const legacy = JSON.stringify({ token: secret, arrayToken: arraySecret, city: 'Paris', cities: ['Paris', 'London'], count: 7 });await shared.store.update(root, 'bot', () => {}, env => {env.automations!.routine!.prepared = { runId: 'structured-run', prompt: '', direct: legacy };});diff --git a/apps/desktop/src/main/bot-import/__tests__/process.test.ts b/apps/desktop/src/main/bot-import/__tests__/process.test.tsindex 0c4d455e8d..6ce13bcd91 100644--- a/apps/desktop/src/main/bot-import/__tests__/process.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/process.test.ts@@ -26,6 +26,20 @@ it('masks encoded and decoded URL credentials without mutating the private conneexpect(output).not.toContain('fake-collision-token');});+it('keeps credential context through array and object values without masking ordinary siblings', () => {+ const original = {+ token: ['fixture-first-secret', ['fixture-second-secret', { value: 'fixture-third-secret' }]],+ profile: { api_key: { current: ['fixture-fourth-secret'] }, cities: ['Paris', 'London'] },+ features: ['true', 'false'], count: 7,+ };+ const before = JSON.stringify(original);+ const masks = importedContentRedactions({ env: {}, mcp: [], credentials: [{ id: 'fixture', format: 'json', value: original }] });+ const output = redactEnvironmentValues('fixture-first-secret fixture-second-secret fixture-third-secret fixture-fourth-secret Paris London true false 7', masks);+ for (const secret of ['fixture-first-secret', 'fixture-second-secret', 'fixture-third-secret', 'fixture-fourth-secret']) expect(output).not.toContain(secret);+ expect(output).toContain('Paris London true false 7');+ expect(JSON.stringify(original)).toBe(before);+});+it('keeps locale/region configuration and ordinary words intact while masking unknown short credentials as tokens', () => {const env = { REGION: 'us', LANG: 'en', LC_ALL: 'en_US.UTF-8', AWS_REGION: 'us-east-1', PRIVATE: 'xy', ARBITRARY: 'fixture-private-value' };const value = { status: 'success', language: 'en', region: 'us', detail: 'English status in us-east-1; private xy / fixture-private-value' };diff --git a/apps/desktop/src/main/bot-import/connectionCatalog.ts b/apps/desktop/src/main/bot-import/connectionCatalog.tsindex 1c0c97cb28..da3c782de8 100644--- a/apps/desktop/src/main/bot-import/connectionCatalog.ts+++ b/apps/desktop/src/main/bot-import/connectionCatalog.ts@@ -62,11 +62,16 @@ export function importedContentRedactions(environment: Pick<CompanionEnvironment...Object.values(environment.contentRedactions ?? {}),...environment.mcp.flatMap(server => Object.values(connectionRedactions(server, environment.env))),...monitorUrls.flatMap(url => urlCredentialValues(url, true))];- const collect = (value: unknown): void => {+ const collect = (value: unknown, credentialValue = false): void => {+ if (typeof value === 'string') {+ if (credentialValue) values.push(value);+ return;+ }if (!value || typeof value !== 'object') return;for (const [key, child] of Object.entries(value)) {- if (typeof child === 'string' && /^(?:key|api[_-]?key|.*token|.*secret|.*password|authorization|access|refresh)$/i.test(key)) values.push(child);- else collect(child);+ // Credential-bearing containers remain private through array indices and+ // nested objects; unrelated sibling fields keep their own classification.+ collect(child, credentialValue || /^(?:key|api[_-]?key|.*token|.*secret|.*password|authorization|access|refresh)$/i.test(key));}};for (const credential of environment.credentials) collect(credential.value);