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): fail closed on Git helpers and shell hooks
MagicLizib406ba874fdb
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 4080798b0d..754b33ea4c 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@@ -386,9 +386,9 @@ describe('GitCredentialHistory', () => {if (process.platform === 'win32') return;const input = '[http]\nextraHeader = PRIVATE_FIXTURE=stdin-config\n';for (const args of [['--fil', '/dev/stdin', 'http.extraHeader'], ['-f/dev/stdin', '--type', 'path', 'http.extraHeader']]) {- const output = execFileSync('git', ['config', ...args], { cwd: repo, input, encoding: 'utf8' });+ const command = 'printf ' + JSON.stringify(input) + ' | git config ' + args.join(' ');+ const output = execFileSync('sh', ['-c', command], { cwd: repo, encoding: 'utf8' });expect(output).toContain('PRIVATE_FIXTURE=stdin-config');- const command = "printf '[http]\\nextraHeader = PRIVATE_FIXTURE=stdin-config\\n' | git config " + args.join(' ');await requiresCredentialConfirmation(history, command);}});@@ -397,7 +397,7 @@ describe('GitCredentialHistory', () => {const history = new GitCredentialHistory();git('config', 'http.extraHeader', 'PRIVATE_FIXTURE=regexp-query');expect(await provesSafe(history, 'git config --get user.name')).toBe(true);- for (const option of ['--get-r', '--get-reg']) {+ for (const option of ['--get-r', '--get-re', '--get-reg']) {expect(git('config', option, '.*')).toContain('PRIVATE_FIXTURE=regexp-query');const command = 'git config ' + option + " '.*'";expect(await provesSafe(history, command), command).toBe(false);@@ -405,6 +405,72 @@ describe('GitCredentialHistory', () => {}});+ it('keeps consent for Git reads that cannot enter the readonly probe path', async () => {+ const history = new GitCredentialHistory();+ expect(await provesSafe(history, 'git diff --cached')).toBe(true);+ write('.env', 'PRIVATE_FIXTURE=non-probed-read\n');+ git('add', '.env');+ for (const args of [+ ['--literal-pathspecs', 'diff', '--cached'],+ ['--git-dir=' + path.join(repo, '.git'), '--work-tree=' + repo, 'diff', '--cached'],+ ['diff', '--ext-diff', '--cached'],+ ['diff', '--textconv', '--cached'],+ ['status', '-v'],+ ]) {+ expect(git(...args)).toContain('PRIVATE_FIXTURE=non-probed-read');+ await requiresCredentialConfirmation(history, 'git ' + args.map((arg) => JSON.stringify(arg)).join(' '));+ }+ });++ it('keeps consent for configured textconv and external diff helpers', async () => {+ const history = new GitCredentialHistory();+ const credentialFile = path.join(root, '.env');+ const helperFile = path.join(root, 'diff-helper.cjs');+ fs.writeFileSync(credentialFile, 'PRIVATE_FIXTURE=diff-helper\n');+ fs.writeFileSync(helperFile, 'const fs = require("node:fs");\n'+ + 'process.stdout.write(fs.readFileSync(' + JSON.stringify(credentialFile) + '));\n'+ + 'process.stdout.write(fs.readFileSync(process.argv[2], "utf8").replaceAll("\\0", ""));\n');+ const helper = [process.execPath, helperFile].map((file) => JSON.stringify(file.split(path.sep).join('/'))).join(' ');+ write('.gitattributes', 'data.bin diff=shared\n');+ write('data.bin', 'old\0bytes\n');+ git('add', '.gitattributes', 'data.bin');+ git('commit', '-q', '--no-gpg-sign', '-m', 'binary data');+ expect(await provesSafe(history, 'git show HEAD')).toBe(true);+ git('config', 'diff.shared.textconv', helper);+ for (const args of [['show', 'HEAD'], ['log', '-p']]) {+ expect(git(...args)).toContain('PRIVATE_FIXTURE=diff-helper');+ const command = 'git ' + args.join(' ');+ expect(await provesSafe(history, command), command).toBe(false);+ await requiresCredentialConfirmation(history, command);+ }+ write('data.bin', 'new\0bytes\n');+ expect(git('diff')).toContain('PRIVATE_FIXTURE=diff-helper');+ await requiresCredentialConfirmation(history, 'git diff');+ git('add', 'data.bin');+ expect(git('diff', '--cached')).toContain('PRIVATE_FIXTURE=diff-helper');+ await requiresCredentialConfirmation(history, 'git diff --cached');+ expect(git('show', '--textconv', 'HEAD:data.bin')).toContain('PRIVATE_FIXTURE=diff-helper');+ await requiresCredentialConfirmation(history, 'git show --textconv HEAD:data.bin');+ expect(await provesSafe(history, 'git log -p -S --no-textconv')).toBe(false);+ expect(git('show', '--no-textconv', 'HEAD')).not.toContain('PRIVATE_FIXTURE=diff-helper');+ expect(await provesSafe(history, 'git show --no-textconv HEAD')).toBe(true);+ git('config', '--unset', 'diff.shared.textconv');+ git('config', 'diff.shared.command', helper);+ expect(git('diff', '--cached')).toContain('PRIVATE_FIXTURE=diff-helper');+ await requiresCredentialConfirmation(history, 'git diff --cached');+ expect(await provesSafe(history, 'git diff --no-ext-diff --cached')).toBe(true);+ git('config', '--unset', 'diff.shared.command');+ git('config', 'diff.external', helper);+ expect(git('diff', '--cached')).toContain('PRIVATE_FIXTURE=diff-helper');+ await requiresCredentialConfirmation(history, 'git diff --cached');+ expect(await provesSafe(history, 'git diff --no-ext-diff --cached')).toBe(true);+ git('config', '--unset', 'diff.external');+ vi.stubEnv('GIT_EXTERNAL_DIFF', helper);+ expect(git('diff', '--cached')).toContain('PRIVATE_FIXTURE=diff-helper');+ await requiresCredentialConfirmation(history, 'git diff --cached');+ expect(await provesSafe(history, 'git diff --no-ext-diff --cached')).toBe(true);+ });+it('does not exempt a git read after an earlier shell segment may change state', async () => {const history = new GitCredentialHistory();expect(await provesSafe(history, 'git add -A && git diff --cached')).toBe(false);@@ -535,6 +601,34 @@ describe('GitCredentialHistory', () => {await requiresCredentialConfirmation(history, command);});+ it('keeps confirmation for inherited shell startup hooks and exported functions', async () => {+ const history = new GitCredentialHistory();+ const startupFile = path.join(root, 'bash-env');+ const credentialFile = path.join(root, '.env');+ fs.writeFileSync(credentialFile, 'PRIVATE_FIXTURE=shell-startup\n');+ const payload = 'cat ' + JSON.stringify(credentialFile.split(path.sep).join('/'));+ fs.writeFileSync(startupFile, 'git() { ' + payload + '; }\n');+ expect(await provesSafe(history, 'git diff')).toBe(true);+ vi.stubEnv('BASH_ENV', startupFile);+ if (process.platform !== 'win32') {+ expect(execFileSync('/bin/bash', ['-c', 'git diff'], { cwd: repo, encoding: 'utf8' }))+ .toContain('PRIVATE_FIXTURE=shell-startup');+ }+ for (const command of ['git diff', 'git config --list']) {+ expect(await provesSafe(history, command), command).toBe(false);+ await requiresCredentialConfirmation(history, command);+ }+ vi.stubEnv('BASH_ENV', undefined);+ expect(await provesSafe(history, 'git diff')).toBe(true);+ for (const key of ['ENV', 'ZDOTDIR', 'BASH_FUNC_git%%']) {+ vi.stubEnv(key, key.startsWith('BASH_FUNC_') ? '() { ' + payload + '; }' : startupFile);+ expect(await provesSafe(history, 'git diff'), key).toBe(false);+ await requiresCredentialConfirmation(history, 'git diff');+ vi.stubEnv(key, undefined);+ }+ expect(await provesSafe(history, 'git diff')).toBe(true);+ });+it('keeps asking where the scan does not reach', async () => {const history = new GitCredentialHistory();const outside = path.join(root, 'outside');diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.tsindex 871a12a25d..907444d417 100644--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts@@ -49,16 +49,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'];+const HISTORY_PATHS = ['log', '-m', '--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'] },- show: { sub: 'show', args: ['--name-only', '--format=', '-m', '--no-renames', '--no-relative', '--no-color', '-z'] },- log: { sub: 'log', args: ['--name-only', '--format=', '-m', '--root', '--no-renames', '--no-relative', '--no-color', '-z'] },- whatchanged: { sub: 'log', args: ['--name-only', '--format=', '-m', '--root', '--no-renames', '--no-relative', '--no-color', '-z'] },+ 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'] },+ log: { sub: 'log', args: ['--name-only', '--format=', '-m', '--root', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff'] },+ whatchanged: { sub: 'log', args: ['--name-only', '--format=', '-m', '--root', '--no-renames', '--no-relative', '--no-color', '-z', '--no-textconv', '--no-ext-diff'] },};/** 会在文件名列表里夹进别的内容的输出选项:碰到就不这样核对。 */const MIXED_OUTPUT_OPTION = /^--(?:graph|stat|numstat|shortstat|dirstat|summary|raw|name-|check|compact-summary|patch-with|line-prefix)/;@@ -70,7 +70,7 @@ const VALUELESS_OPTIONS: ReadonlySet<string> = new Set(['-p', '-u', '--patch', '-W', '--function-context', '--cached', '--staged', '--merge-base', '-R','-a', '--text', '-w', '-b', '--ignore-all-space', '--ignore-space-change', '--ignore-blank-lines','--minimal', '--patience', '--histogram', '--word-diff', '--color-words', '--color', '--no-color',- '--no-ext-diff', '--no-prefix', '--full-index', '--binary', '-M', '-C', '-B', '--find-renames', '--no-renames',+ '--no-ext-diff', '--no-textconv', '--no-prefix', '--full-index', '--binary', '-M', '-C', '-B', '--find-renames', '--no-renames','-m', '-c', '--cc', '--root', '--follow', '--full-diff', '--all', '--branches', '--tags', '--remotes','--no-merges', '--merges', '--first-parent', '--reverse', '--oneline', '--decorate', '--no-decorate','--abbrev-commit', '--source', '--left-right', '--date-order', '--topo-order', '-g', '--walk-reflogs',@@ -476,6 +476,27 @@ async function configReadProvesSafe(read: GitRead): Promise<boolean> {});}+async function diffHelpersCannotRun(read: GitRead, cwd: string, timeoutMs: number): Promise<boolean> {+ if (!['diff', 'show', 'log', 'whatchanged', 'status'].includes(read.sub)) return true;+ const disabled = new Set<string>();+ for (const arg of read.args) {+ if (arg !== '--no-textconv' && arg !== '--no-ext-diff') break;+ disabled.add(arg);+ }+ const textconvEnabled = !disabled.has('--no-textconv');+ const externalDiffEnabled = !disabled.has('--no-ext-diff');+ if (externalDiffEnabled && process.env.GIT_EXTERNAL_DIFF !== undefined) return false;+ if (!textconvEnabled && !externalDiffEnabled) return true;+ const entries = (await git(['config', '--list', '-z'], cwd, { timeoutMs })).split('\0');+ return !entries.some((entry) => {+ const newline = entry.indexOf('\n');+ if (newline < 0 || !entry.slice(newline + 1).trim()) return false;+ const key = entry.slice(0, newline);+ return (textconvEnabled && /^diff\..+\.textconv$/i.test(key))+ || (externalDiffEnabled && (/^diff\..+\.command$/i.test(key) || key.toLowerCase() === 'diff.external'));+ });+}+export class GitCredentialHistory {private readonly repos = new Map<string, RepoEntry>();@@ -484,6 +505,8 @@ export class GitCredentialHistory {/** 这些 git 调用(credentials.ts shareCredentialGitReads 的结果)在本机核实后都读不到、打不出凭证。 */async provesSafe(command: string, reads: readonly GitRead[], signal?: AbortSignal): Promise<boolean> {if (reads.length === 0 || GIT_ENV_ASSIGNMENT.test(command) || GIT_CONFIG_ENV_ASSIGNMENT.test(command)) return false;+ if (['BASH_ENV', 'ENV', 'ZDOTDIR'].some((key) => process.env[key] !== undefined)+ || Object.keys(process.env).some((key) => key.startsWith('BASH_FUNC_'))) return false;const searchPath = process.env.PATH;if (!searchPath || searchPath.split(path.delimiter).some((entry) => !path.isAbsolute(entry))) return false;if (reads.some((read) => read.usesInheritedGitRuntime !== true)) return false;@@ -515,6 +538,8 @@ export class GitCredentialHistory {timeoutMs: replacementTimeout,});if (replacements.trim()) return false;+ const helperTimeout = deadline - Date.now();+ if (helperTimeout <= 0 || !(await diffHelpersCannotRun(read, cwd, helperTimeout))) return false;// 指向仓库外的文件时 git diff 不经仓库、直接比较文件。if (read.sub === 'diff' && read.args.some((arg) => !arg.startsWith('-') && isOutside(top, path.resolve(cwd, arg)))) {return false;diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.mdindex 1707ec3ce4..506b383ac4 100644--- a/docs/product-rules/provider-sharing.md+++ b/docs/product-rules/provider-sharing.md@@ -304,6 +304,8 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):`HEAD`)保留确认,不能按干净历史放行。所有历史与内容探针禁用 replacement refs;仓库有 `refs/replace` 或宿主设置了 `GIT_REPLACE_REF_BASE`时不授予内容豁免,避免探针与实际命令使用不同对象;+ 仓库或生效配置中有 textconv / external diff 驱动、或继承了 `GIT_EXTERNAL_DIFF` 时不能只凭文件名+ 豁免,除非能确定该调用已禁用相应驱动;历史与文件列表探针始终禁用这些外部 helper。- 打出 git 配置的命令(`git remote -v` / `get-url` / `show`、读 `git config`、`git var -l`)按受邀者电脑上生效的 git 配置核实:要打出的那些项里没有密钥(地址里嵌的令牌或密码、`http.extraHeader`、密码与令牌类配置项)就不弹卡,有才确认;显式切换配置文件、blob 或配置作用域(含附着参数、短选项@@ -313,7 +315,11 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):- 上述 Git 核实仅用于命令段直接调用 PATH 中的裸 `git`,且沿用宿主环境、PATH 各项为绝对目录时。显式执行文件路径(如 `./git`)、`git.exe`、任何命令包装器(包括 `env`、`command`、`exec`),以及环境变量的赋值、移除或清空(含 PATH、加载器与 Git 配置来源)都无法与探针证明一致,照旧弹卡;+ 宿主继承了 `BASH_ENV` / `ENV` / `ZDOTDIR` 或导出的 Bash 函数时,同样无法证明 shell 启动后仍调用+ 探针使用的 Git,不授予内容与配置读取豁免;`--bare` 这类改变仓库上下文的选项、前面的命令段可能修改 Git 状态、运行环境,或写法认不出时也不能豁免。+ 已知会读取 Git 内容的调用遇到未识别的全局选项、或不能归为静态只读命令时(如 `--ext-diff` /+ `--textconv`)也保留凭证确认,不能因为未进入核实路径就当成不读取凭证;本机默认判定仍不变。- 再收紧(2026-10-12 用户裁决),同样只用于分享任务:命令里直接写着密钥(`https://用户:密码@`、地址里的令牌、`Authorization` 头的取值、常见服务的令牌格式与私钥)、用 `<提交>:<路径>` 写出凭证类文件(`git show HEAD:.aws/credentials`)、`git credential fill` 这类打出保存的登录凭证的命令都要确认。diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex 8d15644a2a..5eed3727a6 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -4857,6 +4857,24 @@ describe('shellCommandReadsCredentials — 分享任务的附加选项', () => {}});+ it('keeps sharing content reads behind consent when Git parsing or readonly classification fails', () => {+ for (const command of [+ 'git --git-dir=/repo/.git --work-tree=/repo diff --cached',+ 'git diff --ext-diff --cached',+ 'git diff --textconv --cached',+ 'git diff --ext-diff -- README.md',+ 'git show --textconv HEAD:README.md',+ 'git cat-file --textconv HEAD:README.md',+ 'git log --name-only --ext-diff HEAD',+ ]) {+ expect(shellCommandReadsCredentials(command, roots), command).toBe(false);+ const collect = vi.fn(() => true);+ expect(shellCommandReadsCredentials(command, roots, { gitContentRead: collect, gitConfigRead: collect }), command).toBe(true);+ expect(collect, command).not.toHaveBeenCalled();+ }+ expect(shellCommandReadsCredentials('git --version', roots, { gitContentRead: () => true, gitConfigRead: () => true })).toBe(false);+ });+it('checks sharing implicit config reads even when flags take positional values', () => {for (const command of ['git config --fil /tmp/config http.extraHeader',diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 23184bd6f6..5b724b1086 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -6398,7 +6398,11 @@ function shellCommandReadsDotenv(if (bin === 'git') {const invocation = parseGitInvocation(tokens, workspaceRoots, opts);- if (!invocation?.sub || !SAFE_GIT_SUBCOMMANDS.has(invocation.sub)) continue;+ if (!invocation?.sub || !SAFE_GIT_SUBCOMMANDS.has(invocation.sub)) {+ if (sharesGitCredentialChecks && !invocation?.sub+ && tokens.slice(1).some((arg) => /^(?:diff|show|log|whatchanged|grep|cat-file|status|blame)$/.test(arg))) return true;+ continue;+ }const credentialArgs = invocation.args.map(credentialText);if (readsCredentialInput) return true;if (invocation.sub === 'grep') {@@ -6415,9 +6419,12 @@ function shellCommandReadsDotenv(}const probesShowObject = opts.gitContentRead !== undefined && invocation.sub === 'show'&& !gitShowHasOnlySafeObjectPaths(invocation.args);- if ((gitContentReadWithoutPath(invocation.sub, invocation.args) || probesShowObject)- && classifyGit(tokens, segment, workspaceRoots, opts) === 'auto-approve'- && !opts.gitContentRead?.({+ const readsContent = gitContentReadWithoutPath(invocation.sub, invocation.args) || probesShowObject;+ const checksContent = readsContent || (sharesGitCredentialChecks+ && /^(?:diff|show|log|whatchanged|grep|cat-file|status|blame)$/.test(invocation.sub));+ const canProbe = checksContent && classifyGit(tokens, segment, workspaceRoots, opts) === 'auto-approve';+ if (checksContent && sharesGitCredentialChecks && !canProbe) return true;+ if (readsContent && canProbe && !opts.gitContentRead?.({sub: invocation.sub,args: invocation.args,cwd: configOverride ? undefined : gitInvocationCwd(tokens, segmentCwds[segmentIndex]),