( importPath: string, basePath: string, allowedDirectories: string[], )
| 402 | } |
| 403 | |
| 404 | export function validateImportPath( |
| 405 | importPath: string, |
| 406 | basePath: string, |
| 407 | allowedDirectories: string[], |
| 408 | ): boolean { |
| 409 | // Reject URLs |
| 410 | if (/^(file|https?):\/\//.test(importPath)) { |
| 411 | return false; |
| 412 | } |
| 413 | |
| 414 | const resolvedPath = path.resolve(basePath, importPath); |
| 415 | |
| 416 | return allowedDirectories.some((allowedDir) => |
| 417 | isSubpath(allowedDir, resolvedPath), |
| 418 | ); |
| 419 | } |
no test coverage detected