fix(security): securely handle root CWD in isTrustedSystemPath

This commit is contained in:
Coco Sheng
2026-05-12 13:13:10 -04:00
parent 811ae89a16
commit ca41e1bad6

View File

@@ -521,7 +521,8 @@ export function isTrustedSystemPath(filePath: string): boolean {
// 1. Explicitly reject paths in current working directory to prevent RCE
const normCwd = normalizePath(process.cwd());
if (normPath === normCwd || normPath.startsWith(normCwd + '/')) {
const relative = path.relative(normCwd, normPath);
if (!relative.startsWith('..') && !path.isAbsolute(relative)) {
return false;
}