fix(exec): escape regex literals in allowlist path matching

This commit is contained in:
User
2026-03-03 04:47:08 +08:00
committed by Peter Steinberger
parent a4927ed8ee
commit 8da8756f76
2 changed files with 23 additions and 7 deletions

View File

@@ -111,6 +111,10 @@ function tryRealpath(value: string): string | null {
}
}
function escapeRegExpLiteral(input: string): string {
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function globToRegExp(pattern: string): RegExp {
let regex = "^";
let i = 0;
@@ -132,7 +136,7 @@ function globToRegExp(pattern: string): RegExp {
i += 1;
continue;
}
regex += ch.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\$&");
regex += escapeRegExpLiteral(ch);
i += 1;
}
regex += "$";