* Resolve a requested path relative to rootDir and validate it is within * the sandbox (symlink-safe). Returns the resolved absolute path.
(requested: string, rootDir: string)
| 25 | * the sandbox (symlink-safe). Returns the resolved absolute path. |
| 26 | */ |
| 27 | async function resolveAndValidate(requested: string, rootDir: string): Promise<string> { |
| 28 | const resolved = path.resolve(rootDir, requested); |
| 29 | if (!(await isPathWithinDir(resolved, rootDir))) { |
| 30 | throw new Error(`Path traversal rejected: ${requested}`); |
| 31 | } |
| 32 | return resolved; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Write a file relative to rootDir. |
no test coverage detected
searching dependent graphs…