Improve sandbox error matching and caching (#24550)

This commit is contained in:
David Pierce
2026-04-07 21:08:18 +00:00
committed by GitHub
parent 9637fb3990
commit adf7b3b717
10 changed files with 324 additions and 51 deletions
+17
View File
@@ -369,6 +369,22 @@ export function isSubpath(parentPath: string, childPath: string): boolean {
);
}
/**
* Type guard to verify a value is a string and does not contain null bytes.
*/
export function isValidPathString(p: unknown): p is string {
return typeof p === 'string' && !p.includes('\0');
}
/**
* Asserts that a value is a valid path string, throwing an Error otherwise.
*/
export function assertValidPathString(p: unknown): asserts p is string {
if (!isValidPathString(p)) {
throw new Error(`Invalid path: ${String(p)}`);
}
}
/**
* Resolves a path to its real path, sanitizing it first.
* - Removes 'file://' protocol if present.
@@ -379,6 +395,7 @@ export function isSubpath(parentPath: string, childPath: string): boolean {
* @returns The resolved real path.
*/
export function resolveToRealPath(pathStr: string): string {
assertValidPathString(pathStr);
let resolvedPath = pathStr;
try {