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 signature verifiers

MagicLizia7b8265bf55e
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 932ec8986f..4ef92a18c4 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
@@ -560,6 +560,61 @@ describe('GitCredentialHistory', () => {
expect(await history.provesSafe('git config --list', reads ?? [], abort.signal)).toBe(false);
});
+ it('keeps consent for signature verifiers including configured and formatted verification', async () => {
+ const history = new GitCredentialHistory();
+ const credentialFile = path.join(root, '.env');
+ const verifierFile = path.join(root, 'signature-verifier.cjs');
+ const invokedFile = path.join(root, 'verifier-invoked');
+ fs.writeFileSync(credentialFile, 'PRIVATE_FIXTURE=signature-verifier\n');
+ fs.writeFileSync(verifierFile, '#!/usr/bin/env node\nconst fs = require("node:fs");\n'
+ + 'fs.writeFileSync(' + JSON.stringify(invokedFile) + ', "called");\n'
+ + 'process.stderr.write(fs.readFileSync(' + JSON.stringify(credentialFile) + '));\n'
+ + 'process.exitCode = 1;\n');
+ fs.chmodSync(verifierFile, 0o700);
+ const verifier = verifierFile.split(path.sep).join('/');
+ const parent = git('rev-parse', 'HEAD').trim();
+ const rawCommit = ['tree ' + git('rev-parse', 'HEAD^{tree}').trim(), 'parent ' + parent,
+ 'author ' + git('var', 'GIT_AUTHOR_IDENT').trim(), 'committer ' + git('var', 'GIT_COMMITTER_IDENT').trim(),
+ 'gpgsig -----BEGIN PGP SIGNATURE-----', ' synthetic-fixture', ' -----END PGP SIGNATURE-----', '', 'verifier fixture', ''].join('\n');
+ const signed = execFileSync('git', ['hash-object', '-t', 'commit', '-w', '--stdin'], {
+ cwd: repo, input: rawCommit, encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'],
+ }).trim();
+ git('update-ref', 'HEAD', signed);
+ expect(await provesSafe(history, 'git show HEAD')).toBe(true);
+ git('config', 'gpg.program', verifier);
+ git('config', 'log.showSignature', 'true');
+ if (process.platform !== 'win32') {
+ for (const args of [['show', 'HEAD'], ['log', '-1']]) {
+ const output = spawnSync('git', args, { cwd: repo, encoding: 'utf8' });
+ expect(output.stdout + output.stderr, args.join(' ')).toContain('PRIVATE_FIXTURE=signature-verifier');
+ }
+ fs.unlinkSync(invokedFile);
+ }
+ for (const command of ['git show HEAD', 'git log -1', 'git log --format=%G?', 'git log --format=%GG']) {
+ expect(await provesSafe(history, command), command).toBe(false);
+ await requiresCredentialConfirmation(history, command);
+ expect(fs.existsSync(invokedFile), command).toBe(false);
+ }
+ await requiresCredentialConfirmation(history, 'git log --show-signature -1');
+ git('config', '--unset', 'gpg.program');
+ expect(await provesSafe(history, 'git show HEAD')).toBe(false);
+ git('config', 'log.showSignature', 'false');
+ expect(await provesSafe(history, 'git show HEAD')).toBe(true);
+ for (const key of ['gpg.openpgp.program', 'gpg.ssh.program', 'gpg.x509.program']) {
+ git('config', key, verifier);
+ expect(await provesSafe(history, 'git show HEAD'), key).toBe(false);
+ git('config', '--unset', key);
+ }
+ for (const key of ['format.pretty', 'pretty.fixture']) {
+ git('config', key, '%G?');
+ expect(await provesSafe(history, 'git log --oneline'), key).toBe(false);
+ git('config', '--unset', key);
+ }
+ expect(await provesSafe(history, 'git log --format=%GG')).toBe(false);
+ expect(await provesSafe(history, 'git show HEAD')).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 d5c0775fb5..bdc6e0958b 100644
--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
@@ -57,9 +57,9 @@ const HISTORY_PATHS = ['log', '-m', '--root', '--no-renames', '--diff-filter=A',
*/
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'] },
- 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'] },
+ 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'] },
};
/** 会在文件名列表里夹进别的内容的输出选项:碰到就不这样核对。 */
const MIXED_OUTPUT_OPTION = /^--(?:graph|stat|numstat|shortstat|dirstat|summary|raw|name-|check|compact-summary|patch-with|line-prefix)/;
@@ -486,6 +486,10 @@ async function configReadProvesSafe(read: GitRead, deadline: number): Promise<bo
async function diffHelpersCannotRun(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];
+ return arg.includes('%G') || (name.startsWith('--') && name.length > 2 && '--show-signature'.startsWith(name));
+ })) return false;
const disabled = new Set<string>();
for (const arg of read.args) {
if (arg !== '--no-textconv' && arg !== '--no-ext-diff') break;
@@ -498,8 +502,12 @@ async function diffHelpersCannotRun(read: GitRead, cwd: string, timeoutMs: numbe
return !entries.some((entry) => {
const newline = entry.indexOf('\n');
const key = newline < 0 ? entry : entry.slice(0, newline);
- if (key.toLowerCase() === 'core.fsmonitor') return true;
- if (newline < 0 || !entry.slice(newline + 1).trim()) return false;
+ const lowered = key.toLowerCase();
+ if (lowered === 'core.fsmonitor' || /^gpg(?:\..+)?\.program$/i.test(key)) return true;
+ const 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;
+ if ((lowered === 'format.pretty' || lowered.startsWith('pretty.')) && value.includes('%G')) return true;
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 48c3d68799..cbaaeda06a 100644
--- a/docs/product-rules/provider-sharing.md
+++ b/docs/product-rules/provider-sharing.md
@@ -335,6 +335,9 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):
配置中出现 `core.fsmonitor` 时同样保留确认(不假设不同 Git 版本对布尔取值的解释一致),
在读取 index 前拦下它,避免 hook 经 stderr 带出凭证。`git status`、`git ls-files`、只列文件名的
diff 等静态只读调用也要核实运行期 helper;无 helper 时仍可豁免,不改变本机任务默认判定;
+ 签名验证也可能启动外部程序:配置了 `gpg.program` / `gpg.<format>.program`、启用了
+ `log.showSignature`、命令请求 `--show-signature` 或 `%G` 验证格式、配置中的 pretty 格式或别名
+ 含 `%G` 时均保留确认,不假设验证器不会读取或输出凭证;历史与文件列表探针始终禁用签名展示;
`--bare` 这类改变仓库上下文的选项、前面的命令段可能修改 Git 状态、运行环境,或写法认不出时也不能豁免。
已知会读取 Git 内容的调用遇到未识别的全局选项、或不能归为静态只读命令时(如 `--ext-diff` /
`--textconv`)也保留凭证确认,不能因为未进入核实路径就当成不读取凭证;本机默认判定仍不变。