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): check Git mailmap credential sources

MagicLizi6b9de39edcac
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 e8d9c59956..13318aa520 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
@@ -278,6 +278,42 @@ describe('GitCredentialHistory', () => {
expect(await provesSafe(history, 'git log --diff-merges=none -1')).toBe(true);
});
+ it('keeps mailmap credential sources behind consent while allowing ordinary mappings', async () => {
+ const mapping = 'PRIVATE_FIXTURE=mailmap <[email protected]> <[email protected]>\n';
+ const externalCredential = path.join(root, '.env');
+ fs.writeFileSync(externalCredential, mapping);
+ git('config', 'mailmap.file', externalCredential);
+ const history = new GitCredentialHistory();
+ for (const args of [
+ ['log', '--use-mailmap', '--format=%aN', '-1'],
+ ['log', '--format=%aN', '-1'],
+ ['show', '--format=%aN', '--no-patch', 'HEAD'],
+ ]) {
+ expect(git(...args)).toContain('PRIVATE_FIXTURE=mailmap');
+ const command = 'git ' + args.join(' ');
+ expect(await provesSafe(history, command), command).toBe(false);
+ await requiresCredentialConfirmation(history, command);
+ }
+ for (const command of ['git diff', 'git status --short']) {
+ expect(await provesSafe(history, command), command).toBe(true);
+ }
+ const ordinaryMapping = path.join(root, 'authors.mailmap');
+ fs.writeFileSync(ordinaryMapping, 'Mapped Author <[email protected]> <[email protected]>\n');
+ git('config', 'mailmap.file', ordinaryMapping);
+ expect(git('log', '--format=%aN', '-1')).toContain('Mapped Author');
+ expect(await provesSafe(history, 'git log --format=%aN -1')).toBe(true);
+ git('config', '--unset', 'mailmap.file');
+ write('.env', mapping);
+ write('.mailmap', 'Mapped Author <[email protected]> <[email protected]>\n');
+ git('add', '.env', '.mailmap');
+ git('commit', '-qm', 'mapping sources', '--no-gpg-sign');
+ git('config', 'mailmap.blob', 'HEAD:.env');
+ expect(git('log', '--format=%aN', '-1')).toContain('PRIVATE_FIXTURE=mailmap');
+ expect(await provesSafe(history, 'git log --format=%aN -1')).toBe(false);
+ git('config', 'mailmap.blob', 'HEAD:.mailmap');
+ expect(await provesSafe(history, 'git log --format=%aN -1')).toBe(true);
+ });
+
it('checks custom merge drivers only when history reads may remerge commits', async () => {
write('.gitattributes', 'src/app.ts merge=shared\n');
git('add', '.gitattributes');
diff --git a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
index e31c5449fc..c9632c06ef 100644
--- a/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
+++ b/apps/desktop/src/main/remote-agent/executor/gitCredentials.ts
@@ -501,7 +501,39 @@ async function configReadProvesSafe(read: GitRead, deadline: number): Promise<bo
});
}
-async function diffHelpersAllowCredentialProbe(read: GitRead, cwd: string, timeoutMs: number): Promise<boolean> {
+async function mailmapSourcesAllowProbe(
+ read: GitRead, cwd: string, top: string, entries: readonly string[], deadline: number,
+): Promise<boolean> {
+ if (!/^(?:log|show|whatchanged|blame)$/.test(read.sub)) return true;
+ const fileIsSafe = async (file: string): Promise<boolean> => {
+ if (isShareCredentialPath(file)) return false;
+ try {
+ return !isShareCredentialPath(await fsp.realpath(file));
+ } catch (error) {
+ return (error as NodeJS.ErrnoException).code === 'ENOENT';
+ }
+ };
+ // Git reads the worktree mailmap and configured sources even for metadata
+ // formats. Inspect paths, not arbitrary source contents; normal maps stay free.
+ if (!(await fileIsSafe(path.join(top, '.mailmap')))) return false;
+ if (entries.some((entry) => /^mailmap\.file\n/i.test(entry))) {
+ const remaining = deadline - Date.now();
+ if (remaining <= 0) return false;
+ const file = (await git(['config', '--path', '-z', '--get', 'mailmap.file'], cwd, { timeoutMs: remaining })).replace(/\0$/, '');
+ if (file && !(await fileIsSafe(path.resolve(top, file)))) return false;
+ }
+ for (const entry of entries) {
+ if (!/^mailmap\.blob\n/i.test(entry)) continue;
+ const value = entry.slice(entry.indexOf('\n') + 1);
+ if (!value) continue;
+ const objectPath = /^[A-Za-z0-9_./@{}~^+\-]+:(.+)$/.exec(value)?.[1];
+ if (!objectPath || isShareCredentialPath(path.posix.resolve('/', objectPath))) return false;
+ }
+ return true;
+}
+
+async function diffHelpersAllowCredentialProbe(read: GitRead, cwd: string, top: string, timeoutMs: number): Promise<boolean> {
+ const deadline = Date.now() + timeoutMs;
if (!CONTENT_SUBCOMMANDS.has(read.sub) && !read.metadataOnly) return true;
if (read.args.some((arg) => {
const name = arg.split('=')[0];
@@ -516,6 +548,7 @@ async function diffHelpersAllowCredentialProbe(read: GitRead, cwd: string, timeo
const externalDiffEnabled = !disabled.has('--no-ext-diff');
if (externalDiffEnabled && process.env.GIT_EXTERNAL_DIFF !== undefined) return false;
const entries = (await git(['config', '--list', '-z'], cwd, { timeoutMs })).split('\0');
+ if (!(await mailmapSourcesAllowProbe(read, cwd, top, entries, deadline))) return false;
const defaultRemerge = entries.some((entry) => /^log\.diffmerges\n(?:r|remerge)\s*$/i.test(entry));
const mayRemerge = /^(?:log|show|whatchanged)$/.test(read.sub) && read.args.some((arg, index, args) => {
if (arg === '-m') return defaultRemerge;
@@ -659,7 +692,7 @@ export class GitCredentialHistory {
});
if (replacements.trim()) return false;
const helperTimeout = deadline - Date.now();
- if (helperTimeout <= 0 || !(await diffHelpersAllowCredentialProbe(read, cwd, helperTimeout))) return false;
+ if (helperTimeout <= 0 || !(await diffHelpersAllowCredentialProbe(read, cwd, top, 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 6c0d486a61..eddfec8c80 100644
--- a/docs/product-rules/provider-sharing.md
+++ b/docs/product-rules/provider-sharing.md
@@ -362,6 +362,9 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):
不继承重合并配置、不运行 merge driver;普通 Git 查看不因仅存在 merge driver 就额外确认;
`git diff/log/show --check` 的空白错误诊断会输出出错的源码行,因此同样按内容读取核实涉及的
文件;与统计等输出选项组合时也不直接豁免,限定到普通源码的检查仍可免确认;
+ log/show/whatchanged/blame 中的姓名映射也核对来源:`.mailmap` 的真实目标、`mailmap.file` 或
+ `mailmap.blob` 指向凭据路径时保留确认,无法确定路径的 blob 同样确认;普通映射仍可豁免,
+ 不因无关的姓名映射配置让 diff/status 增加确认;
`git var -l` 与单个逻辑变量查询按实际输出检查,包含环境中的 editor/pager 及派生值,不能
仅凭 Git 配置没有密钥就豁免;检查结果留在本机内存,不记录原始输出;
`--bare` 这类改变仓库上下文的选项、前面的命令段可能修改 Git 状态、运行环境,或写法认不出时也不能豁免。