MCPcopy Index your code
hub / github.com/codeaashu/claude-code / isDangerousRemovalPath

Function isDangerousRemovalPath

src/utils/permissions/pathValidation.ts:331–367  ·  view source on GitHub ↗
(resolvedPath: string)

Source from the content-addressed store, hash-verified

329 * - Windows drive root (C:\, D:\) and direct children (C:\Windows, C:\Users)
330 */
331export function isDangerousRemovalPath(resolvedPath: string): boolean {
332 // Callers pass both slash forms; collapse runs so C:\\Windows (valid in
333 // PowerShell) doesn't bypass the drive-child check.
334 const forwardSlashed = resolvedPath.replace(/[\\/]+/g, '/')
335
336 if (forwardSlashed === '*' || forwardSlashed.endsWith('/*')) {
337 return true
338 }
339
340 const normalizedPath =
341 forwardSlashed === '/' ? forwardSlashed : forwardSlashed.replace(/\/$/, '')
342
343 if (normalizedPath === '/') {
344 return true
345 }
346
347 if (WINDOWS_DRIVE_ROOT_REGEX.test(normalizedPath)) {
348 return true
349 }
350
351 const normalizedHome = homedir().replace(/[\\/]+/g, '/')
352 if (normalizedPath === normalizedHome) {
353 return true
354 }
355
356 // Direct children of root: /usr, /tmp, /etc (but not /usr/local)
357 const parentDir = dirname(normalizedPath)
358 if (parentDir === '/') {
359 return true
360 }
361
362 if (WINDOWS_DRIVE_CHILD_REGEX.test(normalizedPath)) {
363 return true
364 }
365
366 return false
367}
368
369/**
370 * Validates a file system path, handling tilde expansion and glob patterns.

Callers 3

Calls

no outgoing calls

Tested by

no test coverage detected