feat: 升级至 v0.3.16 — 工单修复 51 项 + 审查修复 30 项(安全加固/适配器/工具系统/数据层/前端)
This commit is contained in:
@@ -211,6 +211,23 @@ export class GitDiffTool implements IMetonaTool {
|
||||
const pathspec = args.pathspec as string | undefined;
|
||||
const contextLines = Math.max(0, (args.contextLines as number) ?? 3);
|
||||
|
||||
// #19 修复: 校验 pathspec 在工作空间内,防止读取任意仓库差异
|
||||
// 攻击场景:pathspec 传 "../../../other-repo/" 或绝对路径可越权读取工作空间外的 git 差异
|
||||
// resolve 后 isPathWithinWorkspace 校验,glob 字符(*?)不影响前缀校验
|
||||
if (pathspec) {
|
||||
// 审查修复 M18: git magic pathspec(以 : 开头,如 :(glob)**/*.ts)跳过 resolve 校验。
|
||||
// resolve 会把 magic 前缀当普通字符拼接到路径,导致 pathspec 被污染;
|
||||
// git magic 语法本身不构成路径越权风险(git 自身解析 magic 前缀,不指向工作空间外)。
|
||||
if (pathspec.startsWith(':')) {
|
||||
// git magic pathspec,跳过 resolve 校验直接放行
|
||||
} else {
|
||||
const resolved = resolve(context.workspacePath, pathspec);
|
||||
if (!isPathWithinWorkspace(resolved, context.workspacePath)) {
|
||||
return { error: `Path outside workspace: ${pathspec}`, success: false };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const gitArgs = ['diff'];
|
||||
if (cached) gitArgs.push('--cached');
|
||||
gitArgs.push(`--unified=${contextLines}`);
|
||||
|
||||
Reference in New Issue
Block a user