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 command capability URL components
Chris27976e7dcd5c
diff --git a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.tsindex e4f8739083..a0aa14fc70 100644--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts@@ -4,7 +4,7 @@ import path from 'node:path';import os from 'node:os';import { createServer } from 'node:http';import type { Routine } from '@cindy/maker-scheduler';-import { createCompanionEnvironmentStore } from '../environment.js';+import { createCompanionEnvironmentStore, type CompanionEnvironment } from '../environment.js';import { discoverImportSources, inspectImportSource } from '../sources.js';import { validateImportSelection } from '../transfer.js';@@ -278,3 +278,37 @@ it.each(['stdin', 'argv', 'assignment'] as const)('masks nested JSON credentialsawait finishImportedAutomation(root, routine, 'chat', 'structured-run', legacy, true, signal, () => {});expect(shared.message.mock.calls[0]![1].content).toBe(prepared!.direct);});++it.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 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 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 } } : {}) } };+ const environment: CompanionEnvironment = { version: 1, env: source === 'inherited-env' ? { WEBHOOK_URL: url } : {}, mcp: [], credentials: [], automations: {+ routine: { kind: 'openclaw', handover: 'ready', original, sourceRoot: root },+ } };+ await shared.store.write(root, 'bot', environment, () => {});+ const 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);+ 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' });+ 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 => {+ env.automations!.routine!.deliveryProgress = { runId: 'url-run', text: legacy, direct: true, deliveries: [], next: 0 };+ });+ expect((await prepareImportedAutomation(root, routine, 'retry-run', signal, () => {}))?.direct).toBe(result!.direct);+ await finishImportedAutomation(root, routine, 'chat', 'retry-run', 'must reuse pending output', true, signal, () => {});+ expect(shared.message.mock.calls[0]![1].content).toBe(result!.direct);+});diff --git a/apps/desktop/src/main/bot-import/automationRuntime.ts b/apps/desktop/src/main/bot-import/automationRuntime.tsindex b8dca425f3..02d3b62648 100644--- a/apps/desktop/src/main/bot-import/automationRuntime.ts+++ b/apps/desktop/src/main/bot-import/automationRuntime.ts@@ -10,7 +10,7 @@ import { writeImportFiles } from './files.js';import { importedProcessEnvironment, redactEnvironmentValues, runImportedProcess } from './process.js';import { sendImportedDelivery } from './delivery.js';import { importedScriptName, importedScriptInterpreter } from './scripts.js';-import { importedContentRedactions } from './connectionCatalog.js';+import { importedContentRedactions, urlCredentialValues } from './connectionCatalog.js';import type { CompanionEnvironment } from './environment.js';import { importedCommand } from './commandAutomation.js';@@ -24,16 +24,28 @@ async function outputSecrets(environment: CompanionEnvironment, job: Record<striconst values = [command.command, command.cwd, cwd, command.input,...command.args.flatMap(arg => [arg, /^--?[\w-]+=(.+)$/s.exec(arg)?.[1]])].filter((value): value is string => !!value);const structured: CompanionEnvironment['credentials'] = [];- for (const value of new Set(values)) {+ const urlValues: string[] = [];+ const collectUrls = (value: unknown): void => {+ if (typeof value === 'string') {+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) urlValues.push(...urlCredentialValues(value, true));+ } else if (value && typeof value === 'object') Object.values(value).forEach(collectUrls);+ };+ // A URL can carry credentials even in a field named "endpoint". Apply the+ // existing URL policy only to runtime output, preserving imported source text.+ const literals = new Set(values);+ for (const value of new Set([...literals, ...Object.values(environment.env), ...Object.values(command.env)])) {+ collectUrls(value);try {const parsed: unknown = JSON.parse(value);+ collectUrls(parsed);+ if (!literals.has(value)) continue; // Other env values retain their existing classification.if (typeof parsed === 'string') values.push(parsed);else if (parsed && typeof parsed === 'object') structured.push({ id: `command_${structured.length}`, format: 'command-input', value: parsed });} catch { /* Non-JSON command literals still receive exact-value masking. */ }}// Reuse credential-field classification for nested objects/arrays, keeping// ordinary report values readable. Raw and JSON-escaped children are private.- values.push(...Object.values(importedContentRedactions({ env: {}, mcp: [], credentials: structured })));+ values.push(...urlValues, ...Object.values(importedContentRedactions({ env: {}, mcp: [], credentials: structured })));for (const [index, value] of [...new Set(values)].entries()) {secrets[`command_literal_${index}`] = value;const escaped = JSON.stringify(value).slice(1, -1);diff --git a/apps/desktop/src/main/bot-import/connectionCatalog.ts b/apps/desktop/src/main/bot-import/connectionCatalog.tsindex fcf082fcab..4434136817 100644--- a/apps/desktop/src/main/bot-import/connectionCatalog.ts+++ b/apps/desktop/src/main/bot-import/connectionCatalog.ts@@ -27,7 +27,7 @@ export function connectionRedactions(server: ImportedMcpServer, environment: Rec}/** URL credentials can be echoed in encoded or decoded form by a remote service. */-function urlCredentialValues(raw: string, includePath = false): string[] {+export function urlCredentialValues(raw: string, includePath = false): string[] {const values = [raw];try {const url = new URL(raw);