Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companions): mask opaque capability URL paths
zqchris77485a90859c
diff --git a/apps/desktop/src/main/bot-import/README.md b/apps/desktop/src/main/bot-import/README.mdindex fa83db5d4a..f7926cc811 100644--- a/apps/desktop/src/main/bot-import/README.md+++ b/apps/desktop/src/main/bot-import/README.md@@ -116,7 +116,10 @@ omitting it retains normal companion defaults, and a rejected request can be corsecretly copy its expanded value into another selected connection.Public profile/memory/Skill text and routine names/prompts redact all knownsource credentials, including unchecked accounts; memory titles use the same- mask. Routine publication happens before createOnce persists the definition,+ mask. URL paths use an explicit transport-route allowlist; unknown segments are+ private regardless of length or case, including encoded forms and subsequent+ route-looking values. Named local endpoints are exempt only as single loopback+ paths; explicit credential fields always take precedence. Routine publication happens before createOnce persists the definition,and activation compares that same projection so masking does not block takeover.The encrypted checkpoint retains only masks actually matching selected sourcecontent, with stable labels for restart. These values were already embedded indiff --git a/apps/desktop/src/main/bot-import/__tests__/process.test.ts b/apps/desktop/src/main/bot-import/__tests__/process.test.tsindex 026cc37d95..b554b53ba6 100644--- a/apps/desktop/src/main/bot-import/__tests__/process.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/process.test.ts@@ -1,7 +1,7 @@import { expect, it } from 'vitest';import { importedProcessEnvironment, redactEnvironmentData, redactEnvironmentValues } from '../process.js';import { previewImportRedactions } from '../environmentSelection.js';-import { connectionRedactions, importedContentRedactions } from '../connectionCatalog.js';+import { connectionRedactions, importedContentRedactions, redactImportedResult } from '../connectionCatalog.js';it('masks encoded and decoded URL credentials without mutating the private connection', () => {const url = 'https://fake%2Fuser:fake%[email protected]/fake%2Fpath?token=fake%2Bquery';@@ -54,3 +54,28 @@ it('does not turn ordinary scalar settings or MCP endpoint names into content crexpect(redactEnvironmentValues(text, secrets)).toBe(text);expect(redactEnvironmentValues('secret=1', { API_KEY: '1' })).toBe('secret=[API_KEY]');});++it.each(['abcdefghijklmnop', 'abc', 'mcp', 'native-mcp', 'fake%2Ftoken'])('masks capability path %s in results, errors and readable imports', credential => {+ const server = { name: 'fixture', url: `https://example.invalid/hooks/${credential}` };+ const decoded = decodeURIComponent(credential);+ const result = { isError: true, content: [{ type: 'text', text: `Credential: ${credential}; decoded: ${decoded}` }] };+ for (const masks of [connectionRedactions(server, {}), importedContentRedactions({ env: {}, mcp: [server], credentials: [] })]) {+ const output = JSON.stringify(redactImportedResult(result, masks));+ expect(output).not.toContain(credential);+ expect(output).not.toContain(decoded);+ expect(redactEnvironmentValues(decoded, masks)).not.toBe(decoded);+ }+ expect(server.url).toBe(`https://example.invalid/hooks/${credential}`);+});++it('only exempts explicit routing paths, not arbitrary local or remote path shapes', () => {+ for (const origin of ['http://localhost:9000', 'https://example.invalid']) {+ const masks = connectionRedactions({ name: 'fixture', url: `${origin}/api/v1/mcp/abcdefghijklmnop` }, {});+ expect(redactEnvironmentValues('api v1 mcp', masks)).toBe('api v1 mcp');+ expect(redactEnvironmentValues('abcdefghijklmnop', masks)).not.toBe('abcdefghijklmnop');+ }+ const encodedRoute = connectionRedactions({ name: 'fixture', url: 'https://example.invalid/%68ooks/mcp' }, {});+ expect(redactEnvironmentValues('mcp', encodedRoute)).not.toBe('mcp');+ const explicit = connectionRedactions({ name: 'fixture', url: 'http://localhost:9000/native-mcp', headers: { Authorization: 'Bearer native-mcp' } }, {});+ expect(redactEnvironmentValues('native-mcp', explicit)).not.toBe('native-mcp');+});diff --git a/apps/desktop/src/main/bot-import/connectionCatalog.ts b/apps/desktop/src/main/bot-import/connectionCatalog.tsindex 343d548a49..1c0c97cb28 100644--- a/apps/desktop/src/main/bot-import/connectionCatalog.ts+++ b/apps/desktop/src/main/bot-import/connectionCatalog.ts@@ -4,6 +4,11 @@ import type { CompanionEnvironment } from './environment.js';import { fingerprint } from './files.js';import { environmentRedactions, isPublicImportSetting, redactEnvironmentData, redactEnvironmentValues } from './process.js';+// Explicit transport routes only; arbitrary short/lowercase paths can be bearer credentials.+const PUBLIC_MCP_ROUTES = new Set(['api', 'v1', 'v2', 'mcp', 'sse', 'messages', 'hooks', 'webhooks']);+const LOCAL_MCP_ENDPOINTS = new Set(['native-mcp', 'touchdesigner-mcp']);+const CAPABILITY_PATH_PREFIXES = new Set(['hooks', 'webhooks', 'token', 'secret', 'credential', 'key']);+/** Include resolved connection-local values without overwriting same-named imports. */export function connectionRedactions(server: ImportedMcpServer, environment: Record<string, string>): Record<string, string> {const values = [...Object.values(environmentRedactions(environment)), ...Object.values(environmentRedactions(server.env ?? {})), ...Object.values(server.headers ?? {})];@@ -34,10 +39,16 @@ function urlCredentialValues(raw: string, includePath = false): string[] {if (name && value && !isPublicImportSetting(name, value)) values.push(pair.slice(pair.indexOf('=') + 1));}if (includePath) {- // Ordinary endpoint names are routing, not credentials. Keep the full URL- // private; mask only opaque path components that can carry access tokens.- const parts = url.pathname.split('/').filter(part => /(?:token|secret|credential|key)/i.test(part) || part.length >= 32 || part.length >= 20 && /[A-Z0-9_]/.test(part) || /%[0-9a-f]{2}/i.test(part));- values.push(...parts);+ const parts = url.pathname.split('/').filter(Boolean);+ const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);+ let capability = false;+ for (const part of parts) {+ const publicRoute = PUBLIC_MCP_ROUTES.has(part)+ || local && parts.length === 1 && LOCAL_MCP_ENDPOINTS.has(part);+ if (capability || !publicRoute) values.push(part);+ // A route-looking value after a credential introducer is still private.+ if (!publicRoute || CAPABILITY_PATH_PREFIXES.has(part.toLowerCase())) capability = true;+ }}} catch { /* Invalid URLs fail at execution; never publish the literal in errors. */ }return [...new Set(values.filter(value => value && value !== '/').flatMap(value => {