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): mask format-suffixed private key fields

Chrisb7d3a0b2ae5c
diff --git a/apps/desktop/src/main/bot-import/README.md b/apps/desktop/src/main/bot-import/README.md
index e801485665..066beb0784 100644
--- a/apps/desktop/src/main/bot-import/README.md
+++ b/apps/desktop/src/main/bot-import/README.md
@@ -152,6 +152,9 @@ omitting it retains normal companion defaults, and a rejected request can be cor
never for subprocess env or connection authentication. Only selected credential
entries are activated; selected original documents/automation definitions stay
private and unmodified.
+ Structured private-key fields also recognize PEM/Base64 format suffixes and
+ redact their string descendants in published content and command output;
+ ordinary public-key, format-name and key-path fields retain their values.
Profiles supplying different values for one variable are alternatives in the
existing checkboxes; none is guessed by file order. Picking one clears its
conflicting choices, and group selection keeps an existing account choice.
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 1ff7523c71..44d9271cdd 100644
--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
@@ -250,14 +250,16 @@ it.each(['stdin', 'argv', 'assignment', 'env', 'inherited-env'] as const)('masks
const arraySecret = 'fixture-array-secret';
const containerSecret = 'fixture-container-secret';
const privateKey = 'fixture-private-"quoted"\n-key';
+ const encodedKey = 'fixture-encoded-"quoted"\n-key';
const passphrase = 'fixture-passphrase';
const keyField = source === 'stdin' ? 'private_key' : source === 'argv' ? 'privateKey' : 'signing_key';
+ const encodedKeyField = source === 'stdin' ? 'privateKeyPem' : source === 'argv' ? 'private_key_pem' : 'privateKeyBase64';
const input = JSON.stringify({ credentials: [{ token: secret, api_key: [arraySecret] }, containerSecret],
- [keyField]: privateKey, passphrase, passphrases: [passphrase], city: 'Paris report', cities: ['Paris report', 'London'], count: 7 });
+ [keyField]: privateKey, [encodedKeyField]: { copies: [encodedKey] }, passphrase, passphrases: [passphrase], city: 'Paris report', cities: ['Paris report', 'London'], count: 7 });
const read = source === 'stdin' ? 'require("node:fs").readFileSync(0,"utf8")'
: source === 'env' || source === 'inherited-env' ? 'process.env.CONFIG'
: source === 'assignment' ? 'process.argv[1].slice("--config=".length)' : 'process.argv[1]';
- const code = `const input=JSON.parse(${read}); process.stdout.write(JSON.stringify({token:input.credentials[0].token,arrayToken:input.credentials[0].api_key[0],containerToken:input.credentials[1],privateKey:input.${keyField},passphrase:input.passphrase,city:input.city,cities:input.cities,count:input.count}));`;
+ const code = `const input=JSON.parse(${read}); process.stdout.write(JSON.stringify({token:input.credentials[0].token,arrayToken:input.credentials[0].api_key[0],containerToken:input.credentials[1],privateKey:input.${keyField},encodedKey:input.${encodedKeyField}.copies[0],passphrase:input.passphrase,city:input.city,cities:input.cities,count:input.count}));`;
const original = { payload: { kind: 'command', argv: [process.execPath, '-e', code,
...(['argv', 'assignment'].includes(source) ? ['--', source === 'assignment' ? `--config=${input}` : input] : [])],
...(source === 'stdin' ? { input } : {}), ...(source === 'env' ? { env: { CONFIG: input } } : {}), cwd: root } };
@@ -268,14 +270,14 @@ it.each(['stdin', 'argv', 'assignment', 'env', 'inherited-env'] as const)('masks
} }, () => {});
const signal = new AbortController().signal;
const prepared = await prepareImportedAutomation(root, routine, 'structured-run', signal, () => {});
- expect(JSON.parse(prepared!.direct!)).toEqual({ token: expect.stringMatching(/^\[command_literal_/), arrayToken: expect.stringMatching(/^\[command_literal_/), containerToken: expect.stringMatching(/^\[command_literal_/), privateKey: expect.stringMatching(/^\[command_literal_/), passphrase: expect.stringMatching(/^\[command_literal_/), city: 'Paris report', cities: ['Paris report', 'London'], count: 7 });
+ expect(JSON.parse(prepared!.direct!)).toEqual({ token: expect.stringMatching(/^\[command_literal_/), arrayToken: expect.stringMatching(/^\[command_literal_/), containerToken: expect.stringMatching(/^\[command_literal_/), privateKey: expect.stringMatching(/^\[command_literal_/), encodedKey: expect.stringMatching(/^\[command_literal_/), passphrase: expect.stringMatching(/^\[command_literal_/), city: 'Paris report', cities: ['Paris report', 'London'], count: 7 });
const savedEnvironment = (await shared.store.read(root, 'bot', () => {}))!;
expect(savedEnvironment.env).toEqual(environment);
const saved = savedEnvironment.automations!.routine!;
expect(saved.original).toEqual(original);
expect(saved.prepared?.direct).toBe(prepared!.direct);
// Old private output must be masked even when no process is executed again.
- const legacy = JSON.stringify({ token: secret, arrayToken: arraySecret, containerToken: containerSecret, privateKey, passphrase, city: 'Paris report', cities: ['Paris report', 'London'], count: 7 });
+ const legacy = JSON.stringify({ token: secret, arrayToken: arraySecret, containerToken: containerSecret, privateKey, encodedKey, passphrase, city: 'Paris report', cities: ['Paris report', 'London'], count: 7 });
await shared.store.update(root, 'bot', () => {}, env => {
env.automations!.routine!.prepared = { runId: 'structured-run', prompt: '', direct: legacy };
});
diff --git a/apps/desktop/src/main/bot-import/__tests__/process.test.ts b/apps/desktop/src/main/bot-import/__tests__/process.test.ts
index c44f44d503..3cc2909471 100644
--- a/apps/desktop/src/main/bot-import/__tests__/process.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/process.test.ts
@@ -85,16 +85,20 @@ it('preserves OAuth token-type metadata in source files while masking credential
it.each(['credential', 'credentials', 'clientCredentials', 'tokens', 'access_tokens', 'refreshTokens',
'secrets', 'passwords', 'passwds', 'keys', 'api_keys', 'API-KEYS', 'auth', 'authorization', 'cookies',
'private_key', 'privateKey', 'privateKeys', 'SSH_PRIVATE_KEY', 'signing_key', 'signing-key', 'signingKey',
+ 'privateKeyPem', 'private_key_pem', 'private-key-pem', 'SSH_PRIVATE_KEY_PEM',
+ 'privateKeyBase64', 'private_keys_base64', 'signingKeyPem', 'signing_key_base64',
'encryption_key', 'decryptionKey', 'awsSecretAccessKey', 'serviceApiKey', 'passphrase', 'passphrases', 'keyPassphrase', 'pass_phrase', 'pass-phrases'])(
'masks scalar and nested string descendants of the %s credential field', field => {
const original = { [field]: ['fixture-container-secret', { nested: ['fixture-nested-secret'] }],
scalar: { [field]: 'fixture-scalar-secret' }, cities: ['Paris', 'London'], monkeys: ['capuchin'],
- public_key: 'fixture-public-key', sort_key: 'name', keyboard: 'qwerty' };
+ public_key: 'fixture-public-key', sort_key: 'name', keyboard: 'qwerty',
+ publicKeyPem: 'fixture-public-pem', public_key_base64: 'fixture-public-base64',
+ privateKeyFormat: 'pem', privateKeyPath: 'keys/local.pem' };
const before = JSON.stringify(original);
const masks = importedContentRedactions({ env: {}, mcp: [], credentials: [{ id: 'fixture', format: 'json', value: original }] });
- const output = redactEnvironmentValues('fixture-container-secret fixture-nested-secret fixture-scalar-secret Paris London capuchin fixture-public-key name qwerty', masks);
+ const output = redactEnvironmentValues('fixture-container-secret fixture-nested-secret fixture-scalar-secret Paris London capuchin fixture-public-key name qwerty fixture-public-pem fixture-public-base64 pem keys/local.pem', masks);
for (const secret of ['fixture-container-secret', 'fixture-nested-secret', 'fixture-scalar-secret']) expect(output).not.toContain(secret);
- expect(output).toContain('Paris London capuchin fixture-public-key name qwerty');
+ expect(output).toContain('Paris London capuchin fixture-public-key name qwerty fixture-public-pem fixture-public-base64 pem keys/local.pem');
expect(JSON.stringify(original)).toBe(before);
},
);
diff --git a/apps/desktop/src/main/bot-import/connectionCatalog.ts b/apps/desktop/src/main/bot-import/connectionCatalog.ts
index bf387e1fd6..b3ace68940 100644
--- a/apps/desktop/src/main/bot-import/connectionCatalog.ts
+++ b/apps/desktop/src/main/bot-import/connectionCatalog.ts
@@ -9,7 +9,9 @@ const PUBLIC_MCP_ROUTES = new Set(['api', 'v1', 'v2', 'mcp', 'sse', 'messages',
const LOCAL_MCP_ENDPOINTS = new Set(['native-mcp', 'touchdesigner-mcp']);
const CAPABILITY_PATH_PREFIXES = new Set(['hooks', 'webhooks', 'token', 'secret', 'credential', 'key']);
// Credential containers use the same classification as their scalar forms.
-const CREDENTIAL_FIELD = /^(?:keys?|.*(?:api|private|signing|encryption|decryption|secret|access)[_-]?keys?|.*(?:tokens?|secrets?|passwords?|passwds?|pass[_-]?phrases?|credentials?)|auth(?:orization)?|access|refresh|cookies?)$/i;
+// PEM/Base64 suffixes describe key material; metadata such as key paths or
+// format names and public keys must not become global content masks.
+const CREDENTIAL_FIELD = /^(?:keys?|.*(?:api|private|signing|encryption|decryption|secret|access)[_-]?keys?(?:[_-]?(?:pem|base64))?|.*(?:tokens?|secrets?|passwords?|passwds?|pass[_-]?phrases?|credentials?)|auth(?:orization)?|access|refresh|cookies?)$/i;
/** Include resolved connection-local values without overwriting same-named imports. */
export function connectionRedactions(server: ImportedMcpServer, environment: Record<string, string>): Record<string, string> {