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 form-encoded command credentials
Chris90bb1b6bcdd9
diff --git a/apps/desktop/src/main/bot-import/README.md b/apps/desktop/src/main/bot-import/README.mdindex a9c92d78f7..6d46eb1af6 100644--- a/apps/desktop/src/main/bot-import/README.md+++ b/apps/desktop/src/main/bot-import/README.md@@ -590,13 +590,18 @@ is absent from every configured credential map; the original payload remains inlocal encrypted storage for authorized execution.Readable import copies collect credentials from structured argv/stdin as well as-command env. The same literal/JSON/URL traversal is shared with output masking;+command env. The same literal/JSON/URL/form traversal is shared with output masking;publication treats stdin and credential-named options as private literals andexamines other arguments for structured credential fields and capability URLs.Authorization and Proxy-Authorization header literals also mask their credentialpayload without making the scheme or ordinary headers global masks. This coversseparate `-H`/`--header` arguments, `--header=value`, and joined `-Hvalue` formsin both publication and execution-output paths; original argv remains intact.+Form-encoded stdin, argv and command environment values collect credential-named+fields in both wire and decoded form, including repeated fields, percent-encoded+names and `+` spaces. Ordinary form values such as city/day-count/token type stay+readable. Execution retries and final chat publication apply the same masks;+the original form bytes remain in the encrypted command archive.It does not blanket-mask ordinary positional arguments or command settings:doing so corrupts day counts, output formats and subcommands in imported text.Unlabelled opaque positional values are not newly classified as credentials bydiff --git a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.tsindex cacf3d1a98..fbc8b459f0 100644--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts@@ -343,3 +343,37 @@ it.each(['-H', '--header=', '-Hjoined', '--proxy-header'])('masks an echoed authawait finishImportedAutomation(root, routine, 'chat', 'header-run', 'fixture-header-token public report', true, signal, () => {});expect(shared.message.mock.calls[0]![1].content).toBe(result!.direct);});++it.each(['stdin', 'argv', 'assignment', 'env', 'inherited-env'])('masks form credential values from command %s in execution, retries and final publication', async source => {+ const form = 'access_token=fixture-form%2Fsecret%2Bvalue&password=fixture+second+secret&city=Paris&days=7';+ const read = source === 'stdin' ? 'require("node:fs").readFileSync(0,"utf8")'+ : source === 'env' || source === 'inherited-env' ? 'process.env.CONFIG' : 'process.argv[1].replace(/^--data=/, "")';+ const code = `const form=new URLSearchParams(${read});process.stdout.write([form.get("access_token"),form.get("password"),form.get("city"),form.get("days")].join(" | "));`;+ const original = { payload: { kind: 'command', argv: [process.execPath, '-e', code,+ ...(['argv', 'assignment'].includes(source) ? ['--', source === 'assignment' ? `--data=${form}` : form] : [])], cwd: root,+ ...(source === 'stdin' ? { input: form } : {}), ...(source === 'env' ? { env: { CONFIG: form } } : {}) } };+ const environment: Record<string, string> = source === 'inherited-env' ? { CONFIG: form } : {};+ const routine = { id: 'routine', botId: 'bot', prompt: 'Fixture form report' } as Routine;+ await shared.store.write(root, 'bot', { version: 1, env: environment, mcp: [], credentials: [], automations: {+ routine: { kind: 'openclaw', handover: 'ready', original, sourceRoot: root },+ } }, () => {});+ const signal = new AbortController().signal;+ const result = await prepareImportedAutomation(root, routine, 'form-run', signal, () => {});+ for (const secret of ['fixture-form/secret+value', 'fixture second secret']) expect(result!.direct).not.toContain(secret);+ expect(result!.direct).toContain('Paris | 7');+ const saved = (await shared.store.read(root, 'bot', () => {}))!;+ expect(saved.env).toEqual(environment);+ expect(saved.automations!.routine!.original).toEqual(original);+ expect(saved.automations!.routine!.prepared?.direct).toBe(result!.direct);+ const legacy = 'fixture-form/secret+value | fixture second secret | Paris | 7';+ await shared.store.update(root, 'bot', () => {}, env => {+ env.automations!.routine!.prepared = { runId: 'form-run', prompt: '', direct: legacy };+ });+ expect((await prepareImportedAutomation(root, routine, 'form-run', signal, () => {}))?.direct).toBe(result!.direct);+ await shared.store.update(root, 'bot', () => {}, env => {+ env.automations!.routine!.deliveryProgress = { runId: 'form-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/__tests__/environmentSelection.test.ts b/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.tsindex cc5d6fabee..2aacc58b63 100644--- a/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.ts@@ -67,3 +67,19 @@ it.each([}expect(items).toEqual(before);});++it.each(['stdin', 'argv', 'assignment', 'env'])('masks credential fields in form-encoded command %s while retaining public values', source => {+ const form = 'access_token=fixture-form%2Fsecret%2Bvalue&access_token=fixture+second+secret&%70assword=fixture%3Dpassword&city=Paris&days=7&token_type=Bearer';+ const payload = { kind: 'command', argv: ['curl', '--data', ...(source === 'argv' ? [form] : source === 'assignment' ? [`--config=${form}`] : [])],+ ...(source === 'stdin' ? { input: form } : {}), ...(source === 'env' ? { env: { CONFIG: form } } : {}) };+ const items: ImportItem[] = [{ view: { id: 'job', category: 'automations', name: 'Job', selected: true },+ automation: { sourceId: 'job', fingerprint: 'fixture', original: { payload } } }];+ const before = structuredClone(items);+ const secrets = ['fixture-form/secret+value', 'fixture-form%2Fsecret%2Bvalue', 'fixture second secret', 'fixture+second+secret', 'fixture=password', 'fixture%3Dpassword'];+ for (const collect of [previewImportRedactions, selectedImportRedactions]) {+ const readable = redactEnvironmentValues(`${secrets.join('\n')}\nParis 7 Bearer curl --data`, collect(items));+ for (const secret of secrets) expect(readable).not.toContain(secret);+ expect(readable).toContain('Paris 7 Bearer curl --data');+ }+ expect(items).toEqual(before);+});diff --git a/apps/desktop/src/main/bot-import/__tests__/host.test.ts b/apps/desktop/src/main/bot-import/__tests__/host.test.tsindex fccfab1c92..e4bf9bbefb 100644--- a/apps/desktop/src/main/bot-import/__tests__/host.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/host.test.ts@@ -447,7 +447,7 @@ it.each([false, true])('redacts all known credentials from profile/memory copiesit.each([false, true])('publishes command env/argv/stdin credentials safely (command selected: %s)', async selected => {const secret = 'fixture-command-json-token';const nested = 'fixture-command-json-nested';- const literalSecrets = ['fixture-argv-token', 'fixture-stdin-token', 'fixture-plain-token', 'fixture-header-token'];+ const literalSecrets = ['fixture-argv-token', 'fixture-stdin-token', 'fixture-plain-token', 'fixture-header-token', 'fixture-form argv', 'fixture-form%20argv', 'fixture-form/env', 'fixture-form%2Fenv'];const urlSecrets = ['fixture-hook-token', 'fixture-fragment token', 'fixture-fragment%20token','fixture-raw token', 'fixture-raw%20token', 'fixture-raw-query', 'fixture-raw-fragment'];const config = JSON.stringify({ token: secret, credentials: [{ key: nested }],@@ -455,7 +455,7 @@ it.each([false, true])('publishes command env/argv/stdin credentials safely (comunused: { password: 'fixture-unused-command-secret' }, city: 'Paris', count: 7 });const text = `Keep node --mode -e, Paris and 7. ${secret} ${nested} ${urlSecrets.join(' ')} ${literalSecrets.join(' ')}`;const skill = `---\nname: report\ndescription: ${text}\n---\n${text}\n`;- const original = { enabled: false, payload: { kind: 'command', argv: ['node', '-e', '', '--config=' + JSON.stringify({ token: literalSecrets[0], city: 'Paris' }), '--token=' + literalSecrets[2], '-H', 'Authorization: Bearer ' + literalSecrets[3]], input: JSON.stringify({ credentials: [{ privateKeyPem: literalSecrets[1] }], count: 7 }), env: { CONFIG: config, WEBHOOK_URL: 'https://host/hooks/fixture-raw%20token?token=fixture-raw-query#access_token=fixture-raw-fragment' } } };+ const original = { enabled: false, payload: { kind: 'command', argv: ['node', '-e', '', '--config=' + JSON.stringify({ token: literalSecrets[0], city: 'Paris' }), '--token=' + literalSecrets[2], '-H', 'Authorization: Bearer ' + literalSecrets[3], '--data', 'access_token=fixture-form%20argv&city=Paris'], input: JSON.stringify({ credentials: [{ privateKeyPem: literalSecrets[1] }], count: 7 }), env: { CONFIG: config, FORM: 'password=fixture-form%2Fenv&days=7', WEBHOOK_URL: 'https://host/hooks/fixture-raw%20token?token=fixture-raw-query#access_token=fixture-raw-fragment' } } };h.sourceEnabled = false;h.snapshot.items = [{ view: { id: 'task', name: text, category: 'automations', selected, enabled: false }, automation: { sourceId: 'task', fingerprint: 'fixture', original,diff --git a/apps/desktop/src/main/bot-import/commandRedactions.ts b/apps/desktop/src/main/bot-import/commandRedactions.tsindex b3398615a0..083c021f8e 100644--- a/apps/desktop/src/main/bot-import/commandRedactions.ts+++ b/apps/desktop/src/main/bot-import/commandRedactions.ts@@ -13,6 +13,17 @@ export function commandLiteralRedactions(literals: string[], environmentValues:// only its credential payload. Public headers/scheme names are not masks.const header = /^(?:-H)?[\t ]*(?:proxy-)?authorization[\t ]*:[\t ]*(\S+[\t ]+(.+?))[\t ]*$/i.exec(value);if (header) values.push(header[1]!, header[2]!);+ // Form bodies can echo one field independently of the original scalar.+ // Keep both wire and decoded values, including repeated/encoded field names;+ // ordinary form settings are not credentials. Do not interpret URLs or JSON+ // as form bodies (they have their own traversal below).+ if (/^[\w.%+-]+=/.test(value)) for (const match of value.matchAll(/(?:^|&)([^=&]+)=([^&]*)/g)) {+ const pair = `${match[1]}=${match[2]}`;+ const [field] = new URLSearchParams(pair);+ if (field && /^[\w.-]+$/.test(field[0]) && isImportedCredentialField(field[0]) && field[1]) {+ values.push(match[2]!, field[1]);+ }+ }// command-env applies both the credential-field rules and URL component// traversal, including URLs beneath ordinary structured keys like endpoint.structured.push({ id: `command_${structured.length}`, format: 'command-env', value });diff --git a/apps/desktop/src/main/bot-import/environmentSelection.ts b/apps/desktop/src/main/bot-import/environmentSelection.tsindex 97ce719fe5..d8c4974a25 100644--- a/apps/desktop/src/main/bot-import/environmentSelection.ts+++ b/apps/desktop/src/main/bot-import/environmentSelection.ts@@ -80,17 +80,11 @@ function importRedactions(items: ImportItem[], env: Record<string, string>): RecObject.entries(object(object(item.automation?.original.payload).env)).filter((entry): entry is [string, string] => typeof entry[1] === 'string'),));- // Command env JSON and raw capability URLs can occur in readable copies.- // Reuse the credential-field classifier before preview and publication, not- // just after command execution. Ordinary JSON scalar settings stay unchanged.- const structured = commandEnvironments.flatMap(environment => Object.values(environment)).flatMap<{ id: string; format: string; value: unknown }>((value, index) => {- const resolved = String(resolve(value));- if (/^[a-z][a-z0-9+.-]*:\/\//i.test(resolved)) return [{ id: `command_${index}`, format: 'command-env', value: resolved }];- try {- const parsed: unknown = JSON.parse(resolved);- return parsed && typeof parsed === 'object' ? [{ id: `command_${index}`, format: 'command-env', value: parsed }] : [];- } catch { return []; }- });+ // Env, stdin and argv share form/JSON/URL/header decomposition with execution+ // output. Env values retain their existing whole-value masks below; public+ // scalar settings must not gain blanket decoded-literal masks.+ const environmentValues = Object.values(commandLiteralRedactions([], commandEnvironments+ .flatMap(environment => Object.values(environment)).map(value => String(resolve(value))), false));const commandValues = items.flatMap(item => {const payload = object(item.automation?.original.payload);if (payload.kind !== 'command') return [];@@ -100,12 +94,12 @@ function importRedactions(items: ImportItem[], env: Record<string, string>): Rec...Object.values(commandArgumentRedactions(args.map(arg => String(resolve(arg))))),];});- const literalMasks = Object.fromEntries([...new Set(commandValues)].map((value, index) => [`command_input_${index}`, value]));+ const literalMasks = Object.fromEntries([...new Set([...commandValues, ...environmentValues])].map((value, index) => [`command_input_${index}`, value]));return importedContentRedactions({ env,contentRedactions: { ...Object.fromEntries(commandEnvironments.flatMap(environment => Object.entries(environmentRedactions(environment))).map(([name, value], index) => [`command_${index}_${name}`, value])), ...literalMasks },mcp: items.flatMap(item => item.mcp ? [resolve(item.mcp) as NonNullable<typeof item.mcp>] : []),- credentials: [...items.flatMap(item => item.credential ? [{ id: item.view.id, ...item.credential, value: resolve(item.credential.value) }] : []), ...structured],+ credentials: items.flatMap(item => item.credential ? [{ id: item.view.id, ...item.credential, value: resolve(item.credential.value) }] : []),});}