hoe / Super-main-3 /src /lib /safePaths.ts
Cunt1257's picture
Upload 136 files
f02fdcc verified
Raw
History Blame Contribute Delete
377 Bytes
import path from "path";
export function safeResolve(basePath: string, filePath: string): string {
const resolvedBase = path.resolve(basePath);
const resolvedTarget = path.resolve(resolvedBase, filePath);
if (resolvedTarget === resolvedBase || resolvedTarget.startsWith(resolvedBase + path.sep)) {
return resolvedTarget;
}
throw new Error("Invalid file path");
}