MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / validateGlobPattern

Function validateGlobPattern

src/utils/permissions/pathValidation.ts:278–325  ·  view source on GitHub ↗
(
  cleanPath: string,
  cwd: string,
  toolPermissionContext: ToolPermissionContext,
  operationType: FileOperationType,
)

Source from the content-addressed store, hash-verified

276 * Returns the validation result for the base path where the glob would expand.
277 */
278export 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
327const WINDOWS_DRIVE_ROOT_REGEX = /^[A-Za-z]:\/?$/
328const WINDOWS_DRIVE_CHILD_REGEX = /^[A-Za-z]:\/[^/]+$/

Callers 1

validatePathFunction · 0.85

Calls 6

containsPathTraversalFunction · 0.85
safeResolvePathFunction · 0.85
getFsImplementationFunction · 0.85
isPathAllowedFunction · 0.70
getGlobBaseDirectoryFunction · 0.70
resolveFunction · 0.50

Tested by

no test coverage detected