From dbeba202865517666228dc52224d031bdd665466 Mon Sep 17 00:00:00 2001 From: thzxx Date: Fri, 24 Apr 2026 13:58:19 +0800 Subject: [PATCH] fix(security): add path validation to git tool handler handleGit was missing checkPathAllowed validation on the working directory (cwd), allowing git operations to execute in any directory bypassing the security policy. Added validation for: - The cwd used by all git operations - The clone destination directory (write permission check) --- src/main/tool-handlers-git.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/tool-handlers-git.ts b/src/main/tool-handlers-git.ts index 2ff1a77..c60d124 100644 --- a/src/main/tool-handlers-git.ts +++ b/src/main/tool-handlers-git.ts @@ -12,6 +12,10 @@ export async function handleGit(params: { action: string; path?: string; files?: try { const cwd = params.path ? path.resolve(params.path) : getWorkspaceDir(); + // 安全检查:验证工作目录路径 + const dirCheck = checkPathAllowed(cwd, 'read'); + if (!dirCheck.ok) return { success: false, error: dirCheck.reason }; + async function runGit(args: string[]): Promise<{ stdout: string; stderr: string; code: number }> { return new Promise((resolve) => { const git = spawn('git', args, { cwd, stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env, LANG: 'en_US.UTF-8' } }); @@ -180,6 +184,8 @@ export async function handleGit(params: { action: string; path?: string; files?: case 'clone': { if (!params.url) return { success: false, error: '请提供仓库 URL' }; const destDir = params.path ? path.resolve(params.path) : getWorkspaceDir(); + const cloneDirCheck = checkPathAllowed(destDir, 'write'); + if (!cloneDirCheck.ok) return { success: false, error: cloneDirCheck.reason }; const r = await runGit(['clone', params.url, destDir]); if (r.code !== 0) return { success: false, error: r.stderr }; return { success: true, action: 'clone', url: params.url, destination: destDir };