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(provider-sharing): require consent for Git clean filters

MagicLizi1528ed6933c6
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.ts
index bb1dd5f469..3c79a4278f 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
@@ -426,6 +426,46 @@ describe('GitCredentialHistory', () => {
}
});
+ it('keeps consent for clean and process filters even when diff helpers are disabled', async () => {
+ const history = new GitCredentialHistory();
+ const credentialFile = path.join(root, '.env');
+ const helperFile = path.join(root, 'clean-helper.cjs');
+ const invokedFile = path.join(root, 'filter-invoked');
+ const disabledCommand = 'git diff --no-ext-diff --no-textconv';
+ fs.writeFileSync(credentialFile, 'PRIVATE_FIXTURE=clean-filter\n');
+ fs.writeFileSync(helperFile, 'const fs = require("node:fs");\n'
+ + 'fs.writeFileSync(' + JSON.stringify(invokedFile) + ', "called");\n'
+ + 'process.stdout.write(fs.readFileSync(' + JSON.stringify(credentialFile) + '));\n');
+ const helper = [process.execPath, helperFile].map((file) => JSON.stringify(file.split(path.sep).join('/'))).join(' ');
+ write('.gitattributes', 'safe.txt filter=shared\n');
+ write('safe.txt', 'safe before\n');
+ git('add', '.gitattributes', 'safe.txt');
+ git('commit', '-q', '--no-gpg-sign', '-m', 'filtered file');
+ write('safe.txt', 'safe after\n');
+ expect(await provesSafe(history, disabledCommand)).toBe(true);
+ expect(await provesSafe(history, 'git diff --cached')).toBe(true);
+ git('config', 'filter.shared.clean', helper);
+ expect(git('diff', '--no-ext-diff', '--no-textconv')).toContain('PRIVATE_FIXTURE=clean-filter');
+ expect(fs.existsSync(invokedFile)).toBe(true);
+ fs.unlinkSync(invokedFile);
+ for (const key of ['filter.shared.clean', 'filter.shared.process']) {
+ git('config', key, helper);
+ for (const command of ['git diff', disabledCommand, 'git diff --cached', 'git show HEAD', 'git log -p -- safe.txt', 'git grep safe']) {
+ expect(await provesSafe(history, command), key + ': ' + command).toBe(false);
+ await requiresCredentialConfirmation(history, command);
+ expect(fs.existsSync(invokedFile), key + ': ' + command).toBe(false);
+ }
+ expect(await provesSafe(history, 'git config --get core.autocrlf')).toBe(true);
+ git('config', '--unset', key);
+ expect(await provesSafe(history, disabledCommand)).toBe(true);
+ expect(await provesSafe(history, 'git diff --cached')).toBe(true);
+ }
+ git('config', 'filter.shared.clean', '');
+ git('config', 'filter.shared.process', '');
+ expect(await provesSafe(history, disabledCommand)).toBe(true);
+ expect(fs.existsSync(invokedFile)).toBe(false);
+ });
+
it('keeps consent for configured textconv and external diff helpers', async () => {
const history = new GitCredentialHistory();
const credentialFile = path.join(root, '.env');
diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
index 9c58888df4..846dd4edf8 100644
--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
@@ -482,7 +482,7 @@ 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;
+ if (!CONTENT_SUBCOMMANDS.has(read.sub)) return true;
const disabled = new Set<string>();
for (const arg of read.args) {
if (arg !== '--no-textconv' && arg !== '--no-ext-diff') break;
@@ -491,13 +491,13 @@ async function diffHelpersCannotRun(read: GitRead, cwd: string, timeoutMs: numbe
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))
+ return /^filter\..+\.(?:clean|process)$/i.test(key)
+ || (textconvEnabled && /^diff\..+\.textconv$/i.test(key))
|| (externalDiffEnabled && (/^diff\..+\.command$/i.test(key) || key.toLowerCase() === 'diff.external'));
});
}
diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.md
index f4e59cb70e..0039e79409 100644
--- a/docs/product-rules/provider-sharing.md
+++ b/docs/product-rules/provider-sharing.md
@@ -322,6 +322,9 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):
实际执行器选择 zsh 时,即使没有 `ZDOTDIR`,也要核实系统级 `zshenv` 与 `HOME/.zshenv`(含各自
`.zwc` 缓存)均不存在;发现文件、核实文件状态失败或超时、HOME 不明确、或自定义 zsh 的启动目录
无法核实,都保留确认。此核实每次执行前重做,不读取或运行启动脚本,不沿用仓库历史的缓存;
+ Git 内容读取前还要按当次生效的配置核实 `filter.<driver>.clean` / `.process` 均无非空命令;
+ 即使指定 `--no-textconv` / `--no-ext-diff` 也不能略过过滤器核实。发现配置就保留凭证确认,探针
+ 不运行这些过滤器;移除过滤器后仍可按原有路径核实豁免,不沿用旧配置结论;
`--bare` 这类改变仓库上下文的选项、前面的命令段可能修改 Git 状态、运行环境,或写法认不出时也不能豁免。
已知会读取 Git 内容的调用遇到未识别的全局选项、或不能归为静态只读命令时(如 `--ext-diff` /
`--textconv`)也保留凭证确认,不能因为未进入核实路径就当成不读取凭证;本机默认判定仍不变。