Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(provider-sharing): inspect Git logical variable output before exemption
MagicLizi16fd77dee40e
diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.tsindex 27f816659c..b28b7ddbc1 100644--- a/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.ts+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.ts@@ -1003,6 +1003,47 @@ describe('GitCredentialHistory', () => {expect(await provesSafe(history, 'XDG_CONFIG_HOME=' + path.join(root, 'other-config') + ' git remote -v')).toBe(false);});+ it('checks Git logical variable output including environment and derived values', async () => {+ const history = new GitCredentialHistory();+ const fakeToken = 'ghp_' + '0'.repeat(36);+ const editorEnv = ['GIT_EDITOR', 'GIT_SEQUENCE_EDITOR', 'GIT_PAGER', 'EDITOR', 'VISUAL', 'PAGER'];+ for (const key of editorEnv) vi.stubEnv(key, undefined);+ vi.stubEnv('GIT_EDITOR', 'vi');+ vi.stubEnv('GIT_PAGER', 'less');+ for (const variable of ['-l', 'GIT_EDITOR', 'GIT_SEQUENCE_EDITOR', 'GIT_PAGER']) {+ expect(await provesSafe(history, 'git var ' + variable), variable).toBe(true);+ }+ for (const [key, variables] of [+ ['GIT_EDITOR', ['GIT_EDITOR', 'GIT_SEQUENCE_EDITOR']],+ ['GIT_SEQUENCE_EDITOR', ['GIT_SEQUENCE_EDITOR']],+ ['GIT_PAGER', ['GIT_PAGER']],+ ['EDITOR', ['GIT_EDITOR', 'GIT_SEQUENCE_EDITOR']],+ ['VISUAL', ['GIT_EDITOR', 'GIT_SEQUENCE_EDITOR']],+ ['PAGER', ['GIT_PAGER']],+ ] as const) {+ for (const envKey of editorEnv) vi.stubEnv(envKey, undefined);+ vi.stubEnv('TERM', 'xterm');+ vi.stubEnv('EDITOR', 'vi');+ vi.stubEnv('PAGER', 'less');+ vi.stubEnv(key, fakeToken);+ for (const variable of ['-l', ...variables]) {+ expect(git('var', variable), key + ': ' + variable).toContain(fakeToken);+ const command = 'git var ' + variable;+ expect(await provesSafe(history, command), key + ': ' + command).toBe(false);+ await requiresCredentialConfirmation(history, command);+ }+ expect(await provesSafe(history, 'git config user.name')).toBe(true);+ }+ vi.stubEnv('PAGER', 'less');+ git('config', 'http.extraHeader', 'synthetic-config-secret');+ expect(await provesSafe(history, 'git var -l')).toBe(false);+ expect(await provesSafe(history, 'git var GIT_EDITOR')).toBe(true);+ git('config', '--unset', 'http.extraHeader');+ git('config', 'custom.token', '\nsynthetic-config-secret');+ expect(await provesSafe(history, 'git var -l')).toBe(false);+ expect(await provesSafe(history, 'git var GIT_EDITOR')).toBe(true);+ });+it('fails closed for path selectors that exceed the bounded matcher', async () => {const history = new GitCredentialHistory();const selector = 'a*'.repeat(20) + 'b';diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.tsindex ed521fe227..75dafa210b 100644--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts@@ -471,8 +471,20 @@ async function configReadProvesSafe(read: GitRead, deadline: number): Promise<boconst cwd = await fsp.realpath(read.cwd);const remaining = deadline - Date.now();if (remaining <= 0) return false;+ if (read.sub === 'var') {+ // git var includes logical values derived from the environment, not just+ // config. Inspect exactly the requested output locally without logging it.+ if (read.args.length !== 1 || (read.args[0] !== '-l' && !/^GIT_[A-Z0-9_]+$/.test(read.args[0]))) return false;+ const output = await git(['var', ...read.args], cwd, { timeoutMs: remaining });+ if (textSpellsOutSecret(output)) return false;+ if (read.args[0] !== '-l') return true;+ // -l also prints config values. Preserve NUL-delimited key/value checks+ // below so a multiline password/token value cannot lose its key.+ }const key = requestedConfigKey(read);- const entries = (await git(['config', '--list', '-z'], cwd, { timeoutMs: remaining })).split('\0').filter(Boolean);+ const configRemaining = deadline - Date.now();+ if (configRemaining <= 0) return false;+ const entries = (await git(['config', '--list', '-z'], cwd, { timeoutMs: configRemaining })).split('\0').filter(Boolean);return !entries.some((entry) => {const newline = entry.indexOf('\n');const name = newline < 0 ? entry : entry.slice(0, newline);diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.mdindex ec14f64af3..539d799c35 100644--- a/docs/product-rules/provider-sharing.md+++ b/docs/product-rules/provider-sharing.md@@ -360,6 +360,8 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):重合并历史(`--remerge-diff`、`--diff-merges=remerge` 或配置选择的 remerge 模式)可能运行自定义 `merge.<driver>.driver`,非空时先保留确认。内部历史/文件列表探针固定逐父提交比较,不继承重合并配置、不运行 merge driver;普通 Git 查看不因仅存在 merge driver 就额外确认;+ `git var -l` 与单个逻辑变量查询按实际输出检查,包含环境中的 editor/pager 及派生值,不能+ 仅凭 Git 配置没有密钥就豁免;检查结果留在本机内存,不记录原始输出;`--bare` 这类改变仓库上下文的选项、前面的命令段可能修改 Git 状态、运行环境,或写法认不出时也不能豁免。已知会读取 Git 内容的调用遇到未识别的全局选项、或不能归为静态只读命令时(如 `--ext-diff` /`--textconv`)也保留凭证确认,不能因为未进入核实路径就当成不读取凭证;本机默认判定仍不变。diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex d3f2b0b732..8b6396ee2d 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -5104,6 +5104,17 @@ describe('shellCommandReadsCredentials — 分享任务的附加选项', () => {expect(shellCommandReadsCredentials('git diff -- .env', roots, { gitContentRead: () => true })).toBe(true);});+ it('checks sharing Git logical variables without changing local decisions', () => {+ for (const variable of ['-l', 'GIT_EDITOR', 'GIT_PAGER', 'GIT_SEQUENCE_EDITOR']) {+ const command = 'git var ' + variable;+ expect(shellCommandReadsCredentials(command, roots), command).toBe(false);+ expect(shellCommandReadsCredentials(command, roots, { gitConfigRead: () => false }), command).toBe(true);+ const collect = vi.fn(() => true);+ expect(shellCommandReadsCredentials(command, roots, { gitConfigRead: collect }), command).toBe(false);+ expect(collect).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ sub: 'var', args: [variable] }));+ }+ });+it('gitConfigRead:会打出 git 配置或保存的凭证的调用交给调用方', () => {const printing = ['git remote -v',diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 0633bb75d8..8edb214a54 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -6177,7 +6177,7 @@ const GIT_CONFIG_WRITES: ReadonlySet<string> = new Set([*/function gitPrintsConfig(sub: string, args: readonly string[]): boolean {if (sub === 'credential' || sub.startsWith('credential-')) return true;- if (sub === 'var') return args.includes('-l');+ if (sub === 'var') return true;if (sub === 'remote') {const action = args.find((arg) => !arg.startsWith('-'));return action === 'get-url' || action === 'show'