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): accept standard Git LFS read filters

MagicLizi601d8de9cc5f
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 61c2c7b1c5..3b40ef05fa 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
@@ -480,6 +480,33 @@ describe('GitCredentialHistory', () => {
}
});
+ it('allows ordinary Git reads with standard Git LFS installed without exempting credential files', async () => {
+ const history = new GitCredentialHistory();
+ write('.gitattributes', '*.bin filter=lfs diff=lfs merge=lfs -text\n');
+ commit('source and LFS attributes', 'src/util.ts');
+ write('src/app.ts', 'changed\n');
+ git('config', '--global', 'filter.lfs.clean', 'git-lfs clean -- %f');
+ git('config', '--global', 'filter.lfs.process', 'git-lfs filter-process');
+ for (const command of [
+ 'git diff', 'git diff -- src/app.ts', 'git diff --cached', 'git status --short',
+ 'git show HEAD', 'git log -p -1', 'git grep x -- src',
+ ]) {
+ expect(await provesSafe(history, command), command).toBe(true);
+ }
+ write('.env', 'PRIVATE_FIXTURE=lfs-consent\n');
+ git('add', '.env');
+ expect(await provesSafe(history, 'git diff --cached')).toBe(false);
+ await requiresCredentialConfirmation(history, 'git diff --cached');
+ for (const [key, value] of [
+ ['filter.lfs.clean', 'git-lfs clean -- %f && cat .env'],
+ ['filter.lfs.process', 'git-lfs filter-process; cat .env'],
+ ]) {
+ git('config', key, value);
+ expect(await provesSafe(history, 'git diff -- src/app.ts'), key).toBe(false);
+ git('config', '--unset', key);
+ }
+ });
+
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');
diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
index e0803a1672..9f0f264b92 100644
--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
@@ -484,7 +484,7 @@ async function configReadProvesSafe(read: GitRead, deadline: number): Promise<bo
});
}
-async function diffHelpersCannotRun(read: GitRead, cwd: string, timeoutMs: number): Promise<boolean> {
+async function diffHelpersAllowCredentialProbe(read: GitRead, cwd: string, timeoutMs: number): Promise<boolean> {
if (!CONTENT_SUBCOMMANDS.has(read.sub) && !read.metadataOnly) return true;
if (read.args.some((arg) => {
const name = arg.split('=')[0];
@@ -508,7 +508,12 @@ async function diffHelpersCannotRun(read: GitRead, cwd: string, timeoutMs: numbe
if (lowered === 'log.showsignature') return !/^(?:false|no|off|0)$/i.test(value);
if (newline < 0 || !value) return false;
if ((lowered === 'format.pretty' || lowered.startsWith('pretty.')) && value.includes('%G')) return true;
- return /^filter\..+\.(?:clean|process)$/i.test(key)
+ // Trust the standard installed Git LFS commands, just as we trust Git itself.
+ // This gate prevents accidental credential disclosure, not replaced binaries.
+ // Match the complete key/value so custom drivers and shell suffixes still ask.
+ const standardLfs = (key === 'filter.lfs.clean' && value === 'git-lfs clean -- %f')
+ || (key === 'filter.lfs.process' && value === 'git-lfs filter-process');
+ return (/^filter\..+\.(?:clean|process)$/i.test(key) && !standardLfs)
|| (textconvEnabled && /^diff\..+\.textconv$/i.test(key))
|| (externalDiffEnabled && (/^diff\..+\.command$/i.test(key) || key.toLowerCase() === 'diff.external'));
});
@@ -624,7 +629,7 @@ export class GitCredentialHistory {
});
if (replacements.trim()) return false;
const helperTimeout = deadline - Date.now();
- if (helperTimeout <= 0 || !(await diffHelpersCannotRun(read, cwd, helperTimeout))) return false;
+ if (helperTimeout <= 0 || !(await diffHelpersAllowCredentialProbe(read, cwd, helperTimeout))) return false;
const hook = path.join(commonDir, 'hooks', 'post-index-change');
const hookPresent = await Promise.all([hook, hook + '.exe'].map((file) => fsp.lstat(file).then(
() => true,
diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.md
index edc9568a74..711fcd5a53 100644
--- a/docs/product-rules/provider-sharing.md
+++ b/docs/product-rules/provider-sharing.md
@@ -339,9 +339,12 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):
实际执行器选择 zsh 时,即使没有 `ZDOTDIR`,也要核实系统级 `zshenv` 与 `HOME/.zshenv`(含各自
`.zwc` 缓存)均不存在;发现文件、核实文件状态失败或超时、HOME 不明确、或自定义 zsh 的启动目录
无法核实,都保留确认。此核实每次执行前重做,不读取或运行启动脚本,不沿用仓库历史的缓存;
- Git 内容读取前还要按当次生效的配置核实 `filter.<driver>.clean` / `.process` 均无非空命令;
- 即使指定 `--no-textconv` / `--no-ext-diff` 也不能略过过滤器核实。发现配置就保留凭证确认,探针
- 不运行这些过滤器;移除过滤器后仍可按原有路径核实豁免,不沿用旧配置结论;
+ Git 内容读取前还要按当次生效的配置核实 `filter.<driver>.clean` / `.process`。标准 Git LFS
+ 配置 `filter.lfs.clean=git-lfs clean -- %f` 与 `filter.lfs.process=git-lfs filter-process`
+ 按正常工具使用,不因安装 LFS 就要求普通 Git 查看命令确认;其它非空过滤命令仍保留确认,
+ 探针不运行这些自定义过滤器。即使指定 `--no-textconv` / `--no-ext-diff` 也要核实过滤配置,
+ 不沿用旧配置结论。此处沿用防误发的边界:信任正常安装的 Git / Git LFS,不校验二进制是否被
+ 故意替换;凭证文件、直接写在命令里的密钥与保存的登录凭证仍按原规则确认;
配置中出现 `core.fsmonitor` 时同样保留确认(不假设不同 Git 版本对布尔取值的解释一致),
在读取 index 前拦下它,避免 hook 经 stderr 带出凭证。`git status`、`git ls-files`、只列文件名的
diff 等静态只读调用也要核实运行期 helper;无 helper 时仍可豁免,不改变本机任务默认判定;