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

Function validateGlobPattern

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

Source from the content-addressed store, hash-verified

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