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 remote queries

MagicLizi3cc72026dae8
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 754b33ea4c..0a38b7e3ef 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
@@ -2,7 +2,7 @@
* 供应商分享的受邀者任务:git 查看内容的命令在本机核实仓库读不到凭证类文件时不弹卡(gitCredentials.ts)。
* 用真实的 git 仓库验证扫描范围(历史、reflog、stash、暂存区)与各种照旧弹卡的情况。
*/
-import { execFileSync } from 'node:child_process';
+import { execFileSync, spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -489,6 +489,47 @@ describe('GitCredentialHistory', () => {
}
});
+ it('keeps consent for remote queries that can run transport helpers', async () => {
+ vi.stubEnv('GIT_SSH_COMMAND', undefined);
+ vi.stubEnv('GIT_PROXY_COMMAND', undefined);
+ const history = new GitCredentialHistory();
+ const credentialFile = path.join(root, '.env');
+ const helperFile = path.join(root, 'transport-helper.cjs');
+ fs.writeFileSync(credentialFile, 'PRIVATE_FIXTURE=transport-helper\n');
+ fs.writeFileSync(helperFile, 'process.stderr.write(require("node:fs").readFileSync('
+ + JSON.stringify(credentialFile) + '));\nprocess.exit(1);\n');
+ write('transport-fixture.cjs', fs.readFileSync(helperFile, 'utf8'));
+ const helper = [process.execPath, helperFile].map((file) => JSON.stringify(file.split(path.sep).join('/'))).join(' ');
+ git('remote', 'add', 'origin', 'ssh://example.invalid/repository');
+ for (const variant of [
+ { config: 'core.sshCommand', env: 'GIT_SSH_COMMAND', url: 'ssh://example.invalid/repository', helper },
+ { config: 'core.gitProxy', env: 'GIT_PROXY_COMMAND', url: 'git://transport-fixture.cjs/repository', helper: process.execPath },
+ ]) {
+ git('remote', 'set-url', 'origin', variant.url);
+ git('config', variant.config, variant.helper);
+ for (const source of ['config', 'environment']) {
+ if (source === 'environment') {
+ git('config', '--unset', variant.config);
+ vi.stubEnv(variant.env, variant.helper);
+ }
+ const output = spawnSync('git', ['remote', 'show', 'origin'], { cwd: repo, encoding: 'utf8', timeout: 5_000 });
+ expect(output.error).toBeUndefined();
+ expect(output.stderr).toContain('PRIVATE_FIXTURE=transport-helper');
+ expect(await provesSafe(history, 'git remote show origin'), variant.config + ':' + source).toBe(false);
+ await requiresCredentialConfirmation(history, 'git remote show origin');
+ const local = spawnSync('git', ['remote', 'show', '-n', 'origin'], { cwd: repo, encoding: 'utf8', timeout: 5_000 });
+ expect(local.status).toBe(0);
+ expect(local.stdout + local.stderr).not.toContain('PRIVATE_FIXTURE=transport-helper');
+ expect(await provesSafe(history, 'git remote show -n origin')).toBe(true);
+ expect(await provesSafe(history, 'git remote -v')).toBe(true);
+ expect(await provesSafe(history, 'git remote get-url origin')).toBe(true);
+ }
+ vi.stubEnv(variant.env, undefined);
+ }
+ expect(await provesSafe(history, 'git remote show origin')).toBe(false);
+ expect(await provesSafe(history, 'git remote show -- -n')).toBe(false);
+ });
+
it('lets commands that print the git config run only while the config holds no secrets', async () => {
const history = new GitCredentialHistory();
const token = ['ghp_', '0123456789abcdefghijABCDEFGHIJ012345'].join('');
diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
index 907444d417..3ec40b062f 100644
--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
@@ -456,6 +456,10 @@ function configEntryHoldsSecret(key: string, value: string): boolean {
* (系统、全局、仓库,含 include)核对它会打出的那些项里没有密钥。读别的配置文件(-f / --blob)的不核对。
*/
async function configReadProvesSafe(read: GitRead): Promise<boolean> {
+ if (read.sub === 'remote') {
+ const actionIndex = read.args.findIndex((arg) => !arg.startsWith('-'));
+ if (read.args[actionIndex] === 'show' && read.args[actionIndex + 1] !== '-n') return false;
+ }
const configSources = ['--file', '--blob', '--global', '--system', '--local', '--worktree'];
if (!read.cwd || read.args.some((arg) => {
if (/[$`]/.test(arg) || /^-[^-]*f/.test(arg)) return true;
diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.md
index 506b383ac4..98d5d2efe1 100644
--- a/docs/product-rules/provider-sharing.md
+++ b/docs/product-rules/provider-sharing.md
@@ -306,12 +306,14 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):
时不授予内容豁免,避免探针与实际命令使用不同对象;
仓库或生效配置中有 textconv / external diff 驱动、或继承了 `GIT_EXTERNAL_DIFF` 时不能只凭文件名
豁免,除非能确定该调用已禁用相应驱动;历史与文件列表探针始终禁用这些外部 helper。
- - 打出 git 配置的命令(`git remote -v` / `get-url` / `show`、读 `git config`、`git var -l`)按受邀者
+ - 打出 git 配置的命令(`git remote -v` / `get-url` / `show -n`、读 `git config`、`git var -l`)按受邀者
电脑上生效的 git 配置核实:要打出的那些项里没有密钥(地址里嵌的令牌或密码、`http.extraHeader`、
密码与令牌类配置项)就不弹卡,有才确认;显式切换配置文件、blob 或配置作用域(含附着参数、短选项
组合与长选项缩写)不授予豁免,以免核实的是另一套配置;带取值的选项与单键隐式读取也要核实,
不能把选项的取值计入写配置的参数数目而绕过确认。只有确定的单键读取才缩小核实范围,查询模式、
缩写或键名认不准时按全部配置核实,不能把正则查询的模式当成单个键名放行;
+ `git remote show` 没有在动作后明确用 `-n` 禁用远端查询时不授予豁免,避免 SSH / proxy 等传输
+ helper(含配置、继承环境及系统 SSH 设置)把本机凭证打印到 stdout / stderr;只核对地址不能证明安全。
- 上述 Git 核实仅用于命令段直接调用 PATH 中的裸 `git`,且沿用宿主环境、PATH 各项为绝对目录时。
显式执行文件路径(如 `./git`)、`git.exe`、任何命令包装器(包括 `env`、`command`、`exec`),以及
环境变量的赋值、移除或清空(含 PATH、加载器与 Git 配置来源)都无法与探针证明一致,照旧弹卡;