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): guard remerge drivers and isolate history probes
MagicLizie1c2836fdf1d
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 1252644328..27f816659c 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@@ -254,6 +254,51 @@ describe('GitCredentialHistory', () => {expect(await provesSafe(history, 'git log --diff-merges=none -1')).toBe(true);});+ it('checks custom merge drivers only when history reads may remerge commits', async () => {+ write('.gitattributes', 'src/app.ts merge=shared\n');+ git('add', '.gitattributes');+ git('commit', '-qm', 'merge attributes', '--no-gpg-sign');+ const baseBranch = git('branch', '--show-current').trim();+ git('checkout', '-q', '-b', 'side');+ write('src/app.ts', 'side\n');+ git('commit', '-qam', 'side', '--no-gpg-sign');+ git('checkout', '-q', baseBranch);+ write('src/app.ts', 'main\n');+ git('commit', '-qam', 'main', '--no-gpg-sign');+ expect(spawnSync('git', ['merge', '--no-gpg-sign', 'side'], { cwd: repo }).status).toBe(1);+ write('src/app.ts', 'resolved\n');+ git('add', 'src/app.ts');+ git('commit', '-qm', 'resolve merge', '--no-gpg-sign');+ const credential = path.join(root, '.env');+ const invoked = path.join(root, 'merge-invoked');+ const helperFile = path.join(root, 'merge-helper.cjs');+ fs.writeFileSync(credential, 'PRIVATE_FIXTURE=merge-driver\n');+ fs.writeFileSync(helperFile, 'const fs = require("node:fs");\n'+ + 'fs.writeFileSync(' + JSON.stringify(invoked) + ', "called");\n'+ + 'process.stderr.write(fs.readFileSync(' + JSON.stringify(credential) + '));\nprocess.exit(1);\n');+ const helper = [process.execPath, helperFile].map((file) => JSON.stringify(file.split(path.sep).join('/'))).join(' ');+ git('config', 'merge.shared.driver', helper);+ git('config', 'log.diffMerges', 'remerge');+ const history = new GitCredentialHistory();+ for (const options of [+ ['--remerge-diff'], ['--diff-merges=remerge'], ['--diff-merges', 'r'],+ ['-m', '-p'], ['--diff-merges=on'], ['--diff-merges', 'm'],+ ]) {+ const actual = spawnSync('git', ['log', ...options, '-1'], { cwd: repo, encoding: 'utf8' });+ expect(actual.status).toBe(0);+ expect(actual.stderr).toContain('PRIVATE_FIXTURE=merge-driver');+ fs.unlinkSync(invoked);+ const command = 'git log ' + options.join(' ') + ' -1';+ expect(await provesSafe(history, command), command).toBe(false);+ await requiresCredentialConfirmation(history, command);+ expect(fs.existsSync(invoked), command).toBe(false);+ }+ for (const command of ['git log --oneline -1', 'git log -p -1', 'git diff', 'git status --short', 'git log --dd -1']) {+ expect(await provesSafe(history, command), command).toBe(true);+ expect(fs.existsSync(invoked), command).toBe(false);+ }+ });+it('does not trust path-limited full diffs or commits outside the scanned history', async () => {const history = new GitCredentialHistory();const visible = git('rev-parse', 'HEAD').trim();diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.tsindex 9f0f264b92..ed521fe227 100644--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts@@ -50,16 +50,16 @@ const PSEUDO_REF = /(?:ORIG|FETCH|MERGE|CHERRY_PICK|REVERT|REBASE|BISECT)_HEAD|Aconst GIT_ENV_ASSIGNMENT = /\bGIT_[A-Z0-9_]*\s*=/i;const GIT_CONFIG_ENV_ASSIGNMENT = /\b(?:HOME|XDG_CONFIG_HOME)\s*=/i;/** 列出历史里每个路径(每个路径至少在某次提交里以新增出现)。 */-const HISTORY_PATHS = ['log', '-m', '--root', '--no-renames', '--diff-filter=A', '--name-only', '--format=', '-z', '--no-show-signature', '--no-textconv', '--no-ext-diff'];+const HISTORY_PATHS = ['log', '--diff-merges=separate', '--root', '--no-renames', '--diff-filter=A', '--name-only', '--format=', '-z', '--no-show-signature', '--no-textconv', '--no-ext-diff'];/*** 按原命令只列出会显示的文件(插在原有选项之后,后出现的输出格式生效,见 shownFilesArgs)。合并提交按* 每个父提交分别列、不认改名,只会多列。git grep 的选项不能放在搜索词之后,不在内。*/const SHOWN_FILES: Readonly<Record<string, { sub: string; args: readonly string[] }>> = {diff: { sub: 'diff', args: ['--name-only', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff'] },- show: { sub: 'show', args: ['--name-only', '--format=', '-m', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff', '--no-show-signature'] },- log: { sub: 'log', args: ['--name-only', '--format=', '-m', '--root', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff', '--no-show-signature'] },- whatchanged: { sub: 'log', args: ['--name-only', '--format=', '-m', '--root', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff', '--no-show-signature'] },+ show: { sub: 'show', args: ['--diff-merges=separate', '--name-only', '--format=', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff', '--no-show-signature'] },+ log: { sub: 'log', args: ['--diff-merges=separate', '--name-only', '--format=', '--root', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff', '--no-show-signature'] },+ whatchanged: { sub: 'log', args: ['--diff-merges=separate', '--name-only', '--format=', '--root', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff', '--no-show-signature'] },};/** 会在文件名列表里夹进别的内容的输出选项:碰到就不这样核对。 */const MIXED_OUTPUT_OPTION = /^--(?:graph|stat|numstat|shortstat|dirstat|summary|raw|name-|check|compact-summary|patch-with|line-prefix)/;@@ -499,6 +499,16 @@ async function diffHelpersAllowCredentialProbe(read: GitRead, cwd: string, timeoconst externalDiffEnabled = !disabled.has('--no-ext-diff');if (externalDiffEnabled && process.env.GIT_EXTERNAL_DIFF !== undefined) return false;const entries = (await git(['config', '--list', '-z'], cwd, { timeoutMs })).split('\0');+ const defaultRemerge = entries.some((entry) => /^log\.diffmerges\n(?:r|remerge)\s*$/i.test(entry));+ const mayRemerge = /^(?:log|show|whatchanged)$/.test(read.sub) && read.args.some((arg, index, args) => {+ if (arg === '-m') return defaultRemerge;+ const name = arg.split('=')[0];+ if (!name.startsWith('--') || name.length <= 2) return false;+ if ('--remerge-diff'.startsWith(name)) return true;+ if (!'--diff-merges'.startsWith(name)) return false;+ const mode = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : args[index + 1];+ return mode === 'r' || mode === 'remerge' || (defaultRemerge && (mode === 'on' || mode === 'm'));+ });return !entries.some((entry) => {const newline = entry.indexOf('\n');const key = newline < 0 ? entry : entry.slice(0, newline);@@ -507,6 +517,9 @@ async function diffHelpersAllowCredentialProbe(read: GitRead, cwd: string, timeoconst value = newline < 0 ? '' : entry.slice(newline + 1).trim();if (lowered === 'log.showsignature') return !/^(?:false|no|off|0)$/i.test(value);if (newline < 0 || !value) return false;+ // Reconstructing a merge can run a configured merge driver even for ordinary+ // source paths. Check before any probe; unrelated Git reads stay exempt.+ if (mayRemerge && /^merge\..+\.driver$/i.test(key)) return true;if ((lowered === 'format.pretty' || lowered.startsWith('pretty.')) && value.includes('%G')) return true;// Trust the standard installed Git LFS commands, just as we trust Git itself.// This gate prevents accidental credential disclosure, not replaced binaries.diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.mdindex 711fcd5a53..ec14f64af3 100644--- a/docs/product-rules/provider-sharing.md+++ b/docs/product-rules/provider-sharing.md@@ -357,6 +357,9 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):签名验证也可能启动外部程序:配置了 `gpg.program` / `gpg.<format>.program`、启用了`log.showSignature`、命令请求 `--show-signature` 或 `%G` 验证格式、配置中的 pretty 格式或别名含 `%G` 时均保留确认,不假设验证器不会读取或输出凭证;历史与文件列表探针始终禁用签名展示;+ 重合并历史(`--remerge-diff`、`--diff-merges=remerge` 或配置选择的 remerge 模式)可能运行+ 自定义 `merge.<driver>.driver`,非空时先保留确认。内部历史/文件列表探针固定逐父提交比较,+ 不继承重合并配置、不运行 merge driver;普通 Git 查看不因仅存在 merge driver 就额外确认;`--bare` 这类改变仓库上下文的选项、前面的命令段可能修改 Git 状态、运行环境,或写法认不出时也不能豁免。已知会读取 Git 内容的调用遇到未识别的全局选项、或不能归为静态只读命令时(如 `--ext-diff` /`--textconv`)也保留凭证确认,不能因为未进入核实路径就当成不读取凭证;本机默认判定仍不变。