Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(companions): redact curl userinfo passwords

Chris53f638d93b3b
diff --git a/apps/desktop/src/main/bot-import/README.md b/apps/desktop/src/main/bot-import/README.md
index bc81fa59b5..d17fe5537d 100644
--- a/apps/desktop/src/main/bot-import/README.md
+++ b/apps/desktop/src/main/bot-import/README.md
@@ -602,6 +602,11 @@ 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.
+For curl/curl.exe, `-u`/`--user` and `-U`/`--proxy-user` also contribute the password
+after the first userinfo colon, including joined short and assigned long forms.
+Preview/public copies and runtime/retry output share this extraction. Usernames,
+ordinary colon-containing values, other executables and arguments after `--` do
+not gain userinfo masks; original argv bytes are unchanged.
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 by
diff --git a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
index fbc8b459f0..6cdabccce6 100644
--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
@@ -7,6 +7,7 @@ import type { Routine } from '@cindy/maker-scheduler';
import { createCompanionEnvironmentStore, type CompanionEnvironment } from '../environment.js';
import { discoverImportSources, inspectImportSource } from '../sources.js';
import { validateImportSelection } from '../transfer.js';
+import * as importedProcess from '../process.js';
const shared = vi.hoisted(() => ({ store: null as unknown as ReturnType<typeof createCompanionEnvironmentStore>, message: vi.fn() }));
vi.mock('../runtime.js', () => ({ companionEnvironmentStore: { read: (...args: Parameters<typeof shared.store.read>) => shared.store.read(...args), update: (...args: Parameters<typeof shared.store.update>) => shared.store.update(...args) } }));
@@ -20,7 +21,7 @@ beforeEach(async () => {
shared.store = createCompanionEnvironmentStore({ read: key => values.get(key) ?? null, write: (key, value) => { values.set(key, value); return true; }, remove: key => { values.delete(key); return true; } });
shared.message.mockReset().mockResolvedValue({});
});
-afterEach(async () => { vi.unstubAllGlobals(); vi.unstubAllEnvs(); await fs.rm(root, { recursive: true, force: true }); });
+afterEach(async () => { vi.restoreAllMocks(); vi.unstubAllGlobals(); vi.unstubAllEnvs(); await fs.rm(root, { recursive: true, force: true }); });
it.skipIf(process.platform === 'win32')('executes the default imported script and monitor subtrees after removing the source', async () => {
const sourceRoot = path.join(root, '.hermes');
@@ -377,3 +378,35 @@ it.each(['stdin', 'argv', 'assignment', 'env', 'inherited-env'])('masks form cre
await finishImportedAutomation(root, routine, 'chat', 'retry-run', 'must reuse pending output', true, signal, () => {});
expect(shared.message.mock.calls[0]![1].content).toBe(result!.direct);
});
+
+it.each(['-u', '--user', '-U', '--proxy-user', '-ujoined', '-Ujoined', '--user=', '--proxy-user='])
+('masks curl %s passwords from output, retry caches and final chat', async option => {
+ const userinfo = 'alice:fixture-auth:password';
+ const args = option.endsWith('joined') ? [option.slice(0, 2) + userinfo] : option.endsWith('=') ? [option + userinfo] : [option, userinfo];
+ const original = { payload: { kind: 'command', argv: ['curl', ...args], cwd: root } };
+ const output = 'fixture-auth:password | alice | public report';
+ const run = vi.spyOn(importedProcess, 'runImportedProcess').mockResolvedValue({ stdout: output, exitCode: 0 });
+ const routine = { id: 'routine', botId: 'bot', prompt: 'Fixture curl report' } as Routine;
+ await shared.store.write(root, 'bot', { version: 1, env: {}, mcp: [], credentials: [], automations: {
+ routine: { kind: 'openclaw', handover: 'ready', original, sourceRoot: root },
+ } }, () => {});
+ const signal = new AbortController().signal;
+ const result = await prepareImportedAutomation(root, routine, 'curl-run', signal, () => {});
+ expect(run).toHaveBeenCalledWith(expect.objectContaining({ command: 'curl', args }));
+ expect(result!.direct).toMatch(/^\[command_literal_\d+\] \| alice \| public report$/);
+ expect(result!.direct).toContain('alice | public report');
+ const saved = (await shared.store.read(root, 'bot', () => {}))!;
+ expect(saved.automations!.routine!.original).toEqual(original);
+ expect(saved.automations!.routine!.prepared?.direct).toBe(result!.direct);
+ await shared.store.update(root, 'bot', () => {}, env => {
+ env.automations!.routine!.prepared = { runId: 'curl-run', prompt: '', direct: output };
+ });
+ expect((await prepareImportedAutomation(root, routine, 'curl-run', signal, () => {}))?.direct).toBe(result!.direct);
+ await shared.store.update(root, 'bot', () => {}, env => {
+ env.automations!.routine!.deliveryProgress = { runId: 'curl-run', text: output, 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);
+ expect(run).toHaveBeenCalledTimes(1);
+});
diff --git a/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.ts b/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.ts
index 2aacc58b63..e5232522de 100644
--- a/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/environmentSelection.test.ts
@@ -2,6 +2,7 @@ import { expect, it } from 'vitest';
import { previewImportRedactions, resolveImportReferences, selectedImportRedactions } from '../environmentSelection.js';
import { redactEnvironmentValues } from '../process.js';
import type { ImportItem } from '../types.js';
+import { commandArgumentRedactions } from '../commandRedactions.js';
it('resolves mixed-case Windows references throughout selected MCP and delivery settings', () => {
const env = { api_key: 'fixture-key', Empty: '' };
@@ -83,3 +84,29 @@ it.each(['stdin', 'argv', 'assignment', 'env'])('masks credential fields in form
}
expect(items).toEqual(before);
});
+
+it.each(['-u', '--user', '-U', '--proxy-user', '-ujoined', '-Ujoined', '--user=', '--proxy-user='])
+('masks only the password in curl %s userinfo before publication', option => {
+ const password = 'fixture-curl:password-"quoted"'; const userinfo = `alice:${password}`;
+ const args = option.endsWith('joined') ? [option.slice(0, 2) + userinfo] : option.endsWith('=') ? [option + userinfo] : [option, userinfo];
+ const items: ImportItem[] = [{ view: { id: 'job', category: 'automations', name: 'Job', selected: true },
+ automation: { sourceId: 'job', fingerprint: 'fixture', original: { payload: { kind: 'command', argv: ['/usr/bin/curl', ...args] } } } }];
+ const original = structuredClone(items);
+ for (const collect of [previewImportRedactions, selectedImportRedactions]) {
+ const output = redactEnvironmentValues(`${password}\n${JSON.stringify(password)}\nalice ordinary:value --user`, collect(items));
+ expect(output).not.toContain(password);
+ expect(output).not.toContain(JSON.stringify(password).slice(1, -1));
+ expect(output).toContain('alice ordinary:value --user');
+ }
+ expect(items).toEqual(original);
+});
+
+it('scopes curl userinfo parsing to its executable and options, retaining usernames and ordinary colons', () => {
+ for (const exe of ['curl', 'curl.exe', 'C:\\Windows\\System32\\curl.exe']) {
+ expect(Object.values(commandArgumentRedactions([exe, '-u', 'alice:fixture-curl-password']))).toContain('fixture-curl-password');
+ }
+ for (const args of [['node', '-u', 'alice:fixture-public'], ['curl', '--', '-u', 'alice:fixture-public'],
+ ['curl', '--user', 'alice'], ['curl', '--user', 'alice:'], ['curl', 'ordinary:fixture-public']]) {
+ expect(redactEnvironmentValues('alice ordinary:fixture-public', commandArgumentRedactions(args))).toBe('alice ordinary:fixture-public');
+ }
+});
diff --git a/apps/desktop/src/main/bot-import/__tests__/host.test.ts b/apps/desktop/src/main/bot-import/__tests__/host.test.ts
index 94f8cd23f8..839b1359b1 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 copies
it.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', 'fixture-form argv', 'fixture-form%20argv', 'fixture-form/env', 'fixture-form%2Fenv'];
+ 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', 'fixture-curl-password'];
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 (com
unused: { 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], '--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' } } };
+ const original = { enabled: false, payload: { kind: 'command', argv: ['curl', '-u', 'alice:fixture-curl-password', '--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/automationRuntime.ts b/apps/desktop/src/main/bot-import/automationRuntime.ts
index fe3fdddd7e..287146fc2c 100644
--- a/apps/desktop/src/main/bot-import/automationRuntime.ts
+++ b/apps/desktop/src/main/bot-import/automationRuntime.ts
@@ -13,7 +13,7 @@ import { importedScriptName, importedScriptInterpreter } from './scripts.js';
import { importedContentRedactions } from './connectionCatalog.js';
import type { CompanionEnvironment } from './environment.js';
import { importedCommand } from './commandAutomation.js';
-import { commandLiteralRedactions } from './commandRedactions.js';
+import { commandLiteralRedactions, curlUserinfoPasswords } from './commandRedactions.js';
/** Command literals are private too, including values supplied without env names. */
async function outputSecrets(environment: CompanionEnvironment, job: Record<string, unknown>, command: ReturnType<typeof importedCommand>) {
@@ -23,7 +23,8 @@ async function outputSecrets(environment: CompanionEnvironment, job: Record<stri
if (!command) return secrets;
const cwd = command.cwd ? await fs.realpath(command.cwd).catch(() => undefined) : undefined;
Object.assign(secrets, commandLiteralRedactions(
- [command.command, command.cwd, cwd, command.input, ...command.args].filter((value): value is string => !!value),
+ [command.command, command.cwd, cwd, command.input, ...command.args,
+ ...curlUserinfoPasswords([command.command, ...command.args])].filter((value): value is string => !!value),
[...Object.values(environment.env), ...Object.values(command.env)],
));
return secrets;
diff --git a/apps/desktop/src/main/bot-import/commandRedactions.ts b/apps/desktop/src/main/bot-import/commandRedactions.ts
index 083c021f8e..91b52b97e6 100644
--- a/apps/desktop/src/main/bot-import/commandRedactions.ts
+++ b/apps/desktop/src/main/bot-import/commandRedactions.ts
@@ -45,9 +45,24 @@ export function commandLiteralRedactions(literals: string[], environmentValues:
return secrets;
}
+/** curl -u/-U and long forms carry a password after the first colon. */
+export function curlUserinfoPasswords(argv: string[]): string[] {
+ if (!/^(?:.*[/\\])?curl(?:\.exe)?$/i.test(argv[0] ?? '')) return [];
+ const passwords: string[] = [];
+ for (let index = 1; index < argv.length; index++) {
+ const arg = argv[index]!;
+ if (arg === '--') break;
+ const userinfo = ['-u', '-U', '--user', '--proxy-user'].includes(arg) ? argv[++index]
+ : /^--(?:proxy-)?user=([\s\S]*)$/.exec(arg)?.[1] ?? /^-[uU]([\s\S]+)$/.exec(arg)?.[1];
+ const colon = userinfo?.indexOf(':') ?? -1;
+ if (userinfo && colon >= 0 && colon < userinfo.length - 1) passwords.push(userinfo.slice(colon + 1));
+ }
+ return passwords;
+}
+
/** Public copies retain ordinary CLI syntax/settings, not a blanket argv mask. */
export function commandArgumentRedactions(argv: string[]): Record<string, string> {
- const values: string[] = [];
+ const values = Object.values(commandLiteralRedactions(curlUserinfoPasswords(argv)));
let credentialArgument = false;
for (const arg of argv.slice(1)) {
const option = /^--?([\w-]+)(?:=([\s\S]*))?$/.exec(arg);