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 URL fragment credentials
Chrisfb386932d7f6
diff --git a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.tsindex a0aa14fc70..95eb6ee3f4 100644--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts@@ -281,11 +281,11 @@ it.each(['stdin', 'argv', 'assignment'] as const)('masks nested JSON credentialsit.each(['env', 'inherited-env', 'stdin', 'argv', 'assignment'] as const)('masks capability URL components from command %s before caching or publishing', async source => {const routine = { id: 'routine', botId: 'bot', prompt: 'Fixture URL report' } as Routine;- const url = 'https://fixture-user:[email protected]/hooks/fixture%2Fpath?token=fixture%2Bquery&enabled=true';+ const url = 'https://fixture-user:[email protected]/hooks/fixture%2Fpath?token=fixture%2Bquery&enabled=true#access_token=fixture%2Ffragment%2Bsecret&token_type=Bearer§ion=Introduction';const input = JSON.stringify({ destinations: [{ endpoint: url }], city: 'Paris' });const read = source === 'env' || source === 'inherited-env' ? 'process.env.WEBHOOK_URL': `JSON.parse(${source === 'stdin' ? 'require("node:fs").readFileSync(0,"utf8")' : 'process.argv[1].replace(/^--config=/, "")'}).destinations[0].endpoint`;- const code = `const url=new URL(${read}); const encoded=url.pathname.split("/").pop(); process.stdout.write(JSON.stringify({user:url.username,password:url.password,path:decodeURIComponent(encoded),encoded,query:url.searchParams.get("token"),wireQuery:url.search.slice(1).split("&")[0].split("=")[1],enabled:url.searchParams.get("enabled"),route:url.pathname.split("/")[1],city:"Paris"}));`;+ const code = `const url=new URL(${read}); const encoded=url.pathname.split("/").pop(); const fragment=new URLSearchParams(url.hash.slice(1)); process.stdout.write(JSON.stringify({user:url.username,password:url.password,path:decodeURIComponent(encoded),encoded,query:url.searchParams.get("token"),wireQuery:url.search.slice(1).split("&")[0].split("=")[1],fragment:fragment.get("access_token"),wireFragment:url.hash.slice(1).split("&")[0].split("=")[1],tokenType:fragment.get("token_type"),section:fragment.get("section"),enabled:url.searchParams.get("enabled"),route:url.pathname.split("/")[1],city:"Paris"}));`;const original = { payload: { kind: 'command', argv: [process.execPath, '-e', code,...(['argv', 'assignment'].includes(source) ? ['--', source === 'assignment' ? `--config=${input}` : input] : [])], cwd: root,...(source === 'stdin' ? { input } : {}), ...(source === 'env' ? { env: { WEBHOOK_URL: url } } : {}) } };@@ -296,13 +296,13 @@ it.each(['env', 'inherited-env', 'stdin', 'argv', 'assignment'] as const)('masksconst signal = new AbortController().signal;const result = await prepareImportedAutomation(root, routine, 'url-run', signal, () => {});const output = JSON.parse(result!.direct!);- expect(output).toMatchObject({ enabled: 'true', route: 'hooks', city: 'Paris' });- for (const value of ['fixture-user', 'fixture-password', 'fixture/path', 'fixture%2Fpath', 'fixture+query', 'fixture%2Bquery']) expect(result!.direct).not.toContain(value);+ expect(output).toMatchObject({ enabled: 'true', route: 'hooks', city: 'Paris', tokenType: 'Bearer', section: 'Introduction' });+ for (const value of ['fixture-user', 'fixture-password', 'fixture/path', 'fixture%2Fpath', 'fixture+query', 'fixture%2Bquery', 'fixture/fragment+secret', 'fixture%2Ffragment%2Bsecret']) expect(result!.direct).not.toContain(value);const saved = (await shared.store.read(root, 'bot', () => {}))!;expect(saved.automations!.routine!.original).toEqual(original);expect(saved.env).toEqual(environment.env);expect(saved.automations!.routine!.prepared?.direct).toBe(result!.direct);- const legacy = JSON.stringify({ user: 'fixture-user', password: 'fixture-password', path: 'fixture/path', encoded: 'fixture%2Fpath', query: 'fixture+query', wireQuery: 'fixture%2Bquery', enabled: 'true', route: 'hooks', city: 'Paris' });+ const legacy = JSON.stringify({ user: 'fixture-user', password: 'fixture-password', path: 'fixture/path', encoded: 'fixture%2Fpath', query: 'fixture+query', wireQuery: 'fixture%2Bquery', fragment: 'fixture/fragment+secret', wireFragment: 'fixture%2Ffragment%2Bsecret', tokenType: 'Bearer', section: 'Introduction', enabled: 'true', route: 'hooks', city: 'Paris' });await shared.store.update(root, 'bot', () => {}, env => { env.automations!.routine!.prepared = { runId: 'url-run', prompt: '', direct: legacy }; });expect((await prepareImportedAutomation(root, routine, 'url-run', signal, () => {}))?.direct).toBe(result!.direct);await shared.store.update(root, 'bot', () => {}, env => {diff --git a/apps/desktop/src/main/bot-import/__tests__/connectionProvider.test.ts b/apps/desktop/src/main/bot-import/__tests__/connectionProvider.test.tsindex d143edd39f..61767dd64e 100644--- a/apps/desktop/src/main/bot-import/__tests__/connectionProvider.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/connectionProvider.test.ts@@ -312,9 +312,9 @@ it.each([true, false])('preserves MCP response syntax and isError=%s when enviroit('redacts resolved catalog credentials without changing schema syntax, tool dispatch or connection configuration', async () => {const env = { TOKEN: 'fixture-global-token', TYPE: 'object' };- const connection = { name: 'fixture-server', url: 'https://fixture-user:[email protected]/mcp/fixture-path%2Ftoken?key=fixture-url-key',+ const connection = { name: 'fixture-server', url: 'https://fixture-user:[email protected]/mcp/fixture-path%2Ftoken?key=fixture-url-key#access_token=fixture%2Ffragment%2Bsecret',env: { TOKEN: 'fixture-local-token' }, headers: { Authorization: 'Bearer fixture-header-token', 'X-Api-Key': 'fixture-api-key' } };- const secrets = [env.TOKEN, connection.env.TOKEN, connection.headers.Authorization, 'fixture-header-token', connection.headers['X-Api-Key'], connection.url, 'fixture-user', 'fixture-password', 'fixture-url-key', 'fixture-path%2Ftoken', 'fixture-path/token'];+ const secrets = [env.TOKEN, connection.env.TOKEN, connection.headers.Authorization, 'fixture-header-token', connection.headers['X-Api-Key'], connection.url, 'fixture-user', 'fixture-password', 'fixture-url-key', 'fixture-path%2Ftoken', 'fixture-path/token', 'fixture/fragment+secret', 'fixture%2Ffragment%2Bsecret'];const echo = secrets.join(' ');const secretKey = 'argument_fixture-path/token';const tool: Tool = { name: `read_${connection.env.TOKEN}`, title: echo, description: echo,diff --git a/apps/desktop/src/main/bot-import/__tests__/process.test.ts b/apps/desktop/src/main/bot-import/__tests__/process.test.tsindex 414b86ddfb..2ba3bd041a 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,24 @@ it('masks encoded and decoded URL credentials without mutating the private conneexpect(output).not.toContain('fake-collision-token');});+it.each(['access_token', 'id_token', 'refresh_token'])('masks encoded and decoded %s fragment values while preserving ordinary anchors', field => {+ const secret = 'fixture/fragment+secret';+ const encoded = encodeURIComponent(secret);+ const url = `https://example.invalid/mcp#${field}=${encoded}&token_type=Bearer§ion=Introduction&count=7`;+ const server = { name: 'fixture', url };+ const environment = { env: {}, mcp: [server], credentials: [] };+ for (const masks of [connectionRedactions(server, {}), importedContentRedactions(environment),+ importedContentRedactions({ ...environment, mcp: [] }, [url])]) {+ const output = redactEnvironmentValues(`${secret} ${encoded} Bearer Introduction 7`, masks);+ expect(output).not.toContain(secret);+ expect(output).not.toContain(encoded);+ expect(output).toContain('Bearer Introduction 7');+ }+ expect(server.url).toBe(url);+ const anchors = connectionRedactions({ name: 'fixture', url: 'https://example.invalid/mcp#getting-started' }, {});+ expect(redactEnvironmentValues('getting-started', anchors)).toBe('getting-started');+});+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' }]],diff --git a/apps/desktop/src/main/bot-import/connectionCatalog.ts b/apps/desktop/src/main/bot-import/connectionCatalog.tsindex 4434136817..bfbf913361 100644--- a/apps/desktop/src/main/bot-import/connectionCatalog.ts+++ b/apps/desktop/src/main/bot-import/connectionCatalog.ts@@ -40,6 +40,13 @@ export function urlCredentialValues(raw: string, includePath = false): string[]const [name, value] = [...params.entries()][0] ?? [];if (name && value && !isPublicImportSetting(name, value)) values.push(pair.slice(pair.indexOf('=') + 1));}+ // OAuth-style fragments carry named credentials, but ordinary document+ // anchors and fragment metadata must not become global source-text masks.+ for (const pair of url.hash.slice(1).split('&')) {+ if (!pair.includes('=')) continue;+ const [name, value] = [...new URLSearchParams(pair).entries()][0] ?? [];+ if (name && value && CREDENTIAL_FIELD.test(name)) values.push(value, pair.slice(pair.indexOf('=') + 1));+ }if (includePath) {const parts = url.pathname.split('/').filter(Boolean);const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);