(path: string)
| 132 | * @returns The directory path |
| 133 | */ |
| 134 | export function getDirectoryForPath(path: string): string { |
| 135 | const absolutePath = expandPath(path) |
| 136 | // SECURITY: Skip filesystem operations for UNC paths to prevent NTLM credential leaks. |
| 137 | if (absolutePath.startsWith('\\\\') || absolutePath.startsWith('//')) { |
| 138 | return dirname(absolutePath) |
| 139 | } |
| 140 | try { |
| 141 | const stats = getFsImplementation().statSync(absolutePath) |
| 142 | if (stats.isDirectory()) { |
| 143 | return absolutePath |
| 144 | } |
| 145 | } catch { |
| 146 | // Path doesn't exist or can't be accessed |
| 147 | } |
| 148 | // If it's not a directory or doesn't exist, return the parent directory |
| 149 | return dirname(absolutePath) |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Checks if a path contains directory traversal patterns that navigate to parent directories. |
no test coverage detected