(path: string)
| 107 | * @returns The directory path |
| 108 | */ |
| 109 | export function getDirectoryForPath(path: string): string { |
| 110 | const absolutePath = expandPath(path) |
| 111 | // SECURITY: Skip filesystem operations for UNC paths to prevent NTLM credential leaks. |
| 112 | if (absolutePath.startsWith('\\\\') || absolutePath.startsWith('//')) { |
| 113 | return dirname(absolutePath) |
| 114 | } |
| 115 | try { |
| 116 | const stats = getFsImplementation().statSync(absolutePath) |
| 117 | if (stats.isDirectory()) { |
| 118 | return absolutePath |
| 119 | } |
| 120 | } catch { |
| 121 | // Path doesn't exist or can't be accessed |
| 122 | } |
| 123 | // If it's not a directory or doesn't exist, return the parent directory |
| 124 | return dirname(absolutePath) |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Checks if a path contains directory traversal patterns that navigate to parent directories. |
no test coverage detected