* Check if resolved path is within allowed base paths
(resolvedPath: string, allowedBasePaths: string[])
| 85 | * Check if resolved path is within allowed base paths |
| 86 | */ |
| 87 | function isPathAllowed(resolvedPath: string, allowedBasePaths: string[]): boolean { |
| 88 | if (allowedBasePaths.length === 0) return true; |
| 89 | |
| 90 | return allowedBasePaths.some(basePath => { |
| 91 | const resolvedBasePath = path.resolve(basePath); |
| 92 | return resolvedPath.startsWith(resolvedBasePath + path.sep) || |
| 93 | resolvedPath === resolvedBasePath; |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Validate and sanitize file path to prevent path traversal attacks |
no outgoing calls
no test coverage detected