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): recognize plural credential containers

Chris3722684f3af0
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 b6eae0b751..eb539d5c5c 100644
--- a/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/automationRuntime.test.ts
@@ -248,10 +248,11 @@ it.each(['stdin', 'argv', 'assignment'] as const)('masks nested JSON credentials
const routine = { id: 'routine', botId: 'bot', prompt: 'Fixture structured input' } as Routine;
const secret = 'fixture-nested-"quoted"\n-secret';
const arraySecret = 'fixture-array-secret';
- const input = JSON.stringify({ credentials: [{ token: secret, api_key: [arraySecret] }], city: 'Paris', cities: ['Paris', 'London'], count: 7 });
+ const containerSecret = 'fixture-container-secret';
+ const input = JSON.stringify({ credentials: [{ token: secret, api_key: [arraySecret] }, containerSecret], city: 'Paris', cities: ['Paris', 'London'], count: 7 });
const read = source === 'stdin' ? 'require("node:fs").readFileSync(0,"utf8")'
: 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],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],city:input.city,cities:input.cities,count:input.count}));`;
const original = { payload: { kind: 'command', argv: [process.execPath, '-e', code,
...(source === 'stdin' ? [] : ['--', source === 'assignment' ? `--config=${input}` : input])],
...(source === 'stdin' ? { input } : {}), cwd: root } };
@@ -260,12 +261,12 @@ it.each(['stdin', 'argv', 'assignment'] as const)('masks nested JSON credentials
} }, () => {});
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_/), city: 'Paris', cities: ['Paris', 'London'], count: 7 });
+ expect(JSON.parse(prepared!.direct!)).toEqual({ token: expect.stringMatching(/^\[command_literal_/), arrayToken: expect.stringMatching(/^\[command_literal_/), containerToken: expect.stringMatching(/^\[command_literal_/), city: 'Paris', cities: ['Paris', 'London'], count: 7 });
const saved = (await shared.store.read(root, 'bot', () => {}))!.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, city: 'Paris', cities: ['Paris', 'London'], count: 7 });
+ const legacy = JSON.stringify({ token: secret, arrayToken: arraySecret, containerToken: containerSecret, city: 'Paris', cities: ['Paris', '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 6ce13bcd91..c737753751 100644
--- a/apps/desktop/src/main/bot-import/__tests__/process.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/process.test.ts
@@ -40,6 +40,20 @@ it('keeps credential context through array and object values without masking ord
expect(JSON.stringify(original)).toBe(before);
});
+it.each(['credential', 'credentials', 'clientCredentials', 'tokens', 'access_tokens', 'refreshTokens',
+ 'secrets', 'passwords', 'passwds', 'keys', 'api_keys', 'API-KEYS', 'auth', 'authorization', 'cookies'])(
+ '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'] };
+ 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', 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');
+ expect(JSON.stringify(original)).toBe(before);
+ },
+);
+
it('keeps locale/region configuration and ordinary words intact while masking unknown short credentials as tokens', () => {
const env = { REGION: 'us', LANG: 'en', LC_ALL: 'en_US.UTF-8', AWS_REGION: 'us-east-1', PRIVATE: 'xy', ARBITRARY: 'fixture-private-value' };
const value = { status: 'success', language: 'en', region: 'us', detail: 'English status in us-east-1; private xy / fixture-private-value' };
diff --git a/apps/desktop/src/main/bot-import/connectionCatalog.ts b/apps/desktop/src/main/bot-import/connectionCatalog.ts
index da3c782de8..bcf1b31650 100644
--- a/apps/desktop/src/main/bot-import/connectionCatalog.ts
+++ b/apps/desktop/src/main/bot-import/connectionCatalog.ts
@@ -8,6 +8,8 @@ import { environmentRedactions, isPublicImportSetting, redactEnvironmentData, re
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']);
+// Credential containers use the same classification as their scalar forms.
+const CREDENTIAL_FIELD = /^(?:keys?|api[_-]?keys?|.*(?:tokens?|secrets?|passwords?|passwds?|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> {
@@ -71,7 +73,7 @@ export function importedContentRedactions(environment: Pick<CompanionEnvironment
for (const [key, child] of Object.entries(value)) {
// Credential-bearing containers remain private through array indices and
// nested objects; unrelated sibling fields keep their own classification.
- collect(child, credentialValue || /^(?:key|api[_-]?key|.*token|.*secret|.*password|authorization|access|refresh)$/i.test(key));
+ collect(child, credentialValue || CREDENTIAL_FIELD.test(key));
}
};
for (const credential of environment.credentials) collect(credential.value);