( cleanPath: string, cwd: string, toolPermissionContext: ToolPermissionContext, operationType: FileOperationType, )
| 276 | * Returns the validation result for the base path where the glob would expand. |
| 277 | */ |
| 278 | export function validateGlobPattern( |
| 279 | cleanPath: string, |
| 280 | cwd: string, |
| 281 | toolPermissionContext: ToolPermissionContext, |
| 282 | operationType: FileOperationType, |
| 283 | ): ResolvedPathCheckResult { |
| 284 | if (containsPathTraversal(cleanPath)) { |
| 285 | // For patterns with path traversal, resolve the full path |
| 286 | const absolutePath = isAbsolute(cleanPath) |
| 287 | ? cleanPath |
| 288 | : resolve(cwd, cleanPath) |
| 289 | const { resolvedPath, isCanonical } = safeResolvePath( |
| 290 | getFsImplementation(), |
| 291 | absolutePath, |
| 292 | ) |
| 293 | const result = isPathAllowed( |
| 294 | resolvedPath, |
| 295 | toolPermissionContext, |
| 296 | operationType, |
| 297 | isCanonical ? [resolvedPath] : undefined, |
| 298 | ) |
| 299 | return { |
| 300 | allowed: result.allowed, |
| 301 | resolvedPath, |
| 302 | decisionReason: result.decisionReason, |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | const basePath = getGlobBaseDirectory(cleanPath) |
| 307 | const absoluteBasePath = isAbsolute(basePath) |
| 308 | ? basePath |
| 309 | : resolve(cwd, basePath) |
| 310 | const { resolvedPath, isCanonical } = safeResolvePath( |
| 311 | getFsImplementation(), |
| 312 | absoluteBasePath, |
| 313 | ) |
| 314 | const result = isPathAllowed( |
| 315 | resolvedPath, |
| 316 | toolPermissionContext, |
| 317 | operationType, |
| 318 | isCanonical ? [resolvedPath] : undefined, |
| 319 | ) |
| 320 | return { |
| 321 | allowed: result.allowed, |
| 322 | resolvedPath, |
| 323 | decisionReason: result.decisionReason, |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | const WINDOWS_DRIVE_ROOT_REGEX = /^[A-Za-z]:\/?$/ |
| 328 | const WINDOWS_DRIVE_CHILD_REGEX = /^[A-Za-z]:\/[^/]+$/ |
no test coverage detected