@j0hanz/filesystem-mcp 2.1.6 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +7 -7
  2. package/dist/cli.d.ts +1 -2
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +29 -34
  5. package/dist/cli.js.map +1 -1
  6. package/dist/core/concurrency.d.ts +4 -7
  7. package/dist/core/concurrency.d.ts.map +1 -1
  8. package/dist/core/concurrency.js +4 -12
  9. package/dist/core/concurrency.js.map +1 -1
  10. package/dist/core/cursor.d.ts.map +1 -1
  11. package/dist/core/cursor.js +8 -20
  12. package/dist/core/cursor.js.map +1 -1
  13. package/dist/core/fmt.d.ts +2 -1
  14. package/dist/core/fmt.d.ts.map +1 -1
  15. package/dist/core/fmt.js +8 -15
  16. package/dist/core/fmt.js.map +1 -1
  17. package/dist/core/fs.d.ts +0 -14
  18. package/dist/core/fs.d.ts.map +1 -1
  19. package/dist/core/fs.js +1 -0
  20. package/dist/core/fs.js.map +1 -1
  21. package/dist/core/glob.d.ts +0 -3
  22. package/dist/core/glob.d.ts.map +1 -1
  23. package/dist/core/glob.js +5 -27
  24. package/dist/core/glob.js.map +1 -1
  25. package/dist/core/input-required.d.ts +2 -2
  26. package/dist/core/input-required.d.ts.map +1 -1
  27. package/dist/core/input-required.js.map +1 -1
  28. package/dist/core/path-completer.d.ts.map +1 -1
  29. package/dist/core/path-completer.js +4 -27
  30. package/dist/core/path-completer.js.map +1 -1
  31. package/dist/core/path-utils.d.ts +1 -1
  32. package/dist/core/path-utils.d.ts.map +1 -1
  33. package/dist/core/path-utils.js +2 -2
  34. package/dist/core/path-utils.js.map +1 -1
  35. package/dist/core/path.d.ts +7 -9
  36. package/dist/core/path.d.ts.map +1 -1
  37. package/dist/core/path.js +24 -42
  38. package/dist/core/path.js.map +1 -1
  39. package/dist/core/read.d.ts.map +1 -1
  40. package/dist/core/read.js +6 -23
  41. package/dist/core/read.js.map +1 -1
  42. package/dist/core/schema.d.ts.map +1 -1
  43. package/dist/core/schema.js +19 -74
  44. package/dist/core/schema.js.map +1 -1
  45. package/dist/core/search.d.ts +30 -7
  46. package/dist/core/search.d.ts.map +1 -1
  47. package/dist/core/search.js +63 -21
  48. package/dist/core/search.js.map +1 -1
  49. package/dist/core/store.d.ts.map +1 -1
  50. package/dist/core/store.js +6 -17
  51. package/dist/core/store.js.map +1 -1
  52. package/dist/index.js +15 -42
  53. package/dist/index.js.map +1 -1
  54. package/dist/prompts.d.ts.map +1 -1
  55. package/dist/prompts.js +17 -25
  56. package/dist/prompts.js.map +1 -1
  57. package/dist/resources.d.ts +4 -4
  58. package/dist/resources.d.ts.map +1 -1
  59. package/dist/resources.js +7 -17
  60. package/dist/resources.js.map +1 -1
  61. package/dist/server.d.ts +1 -4
  62. package/dist/server.d.ts.map +1 -1
  63. package/dist/server.js +2 -7
  64. package/dist/server.js.map +1 -1
  65. package/dist/tools/define.d.ts.map +1 -1
  66. package/dist/tools/define.js +35 -61
  67. package/dist/tools/define.js.map +1 -1
  68. package/dist/tools/delete-file.d.ts.map +1 -1
  69. package/dist/tools/delete-file.js +30 -35
  70. package/dist/tools/delete-file.js.map +1 -1
  71. package/dist/tools/edit.d.ts.map +1 -1
  72. package/dist/tools/edit.js +8 -13
  73. package/dist/tools/edit.js.map +1 -1
  74. package/dist/tools/list.d.ts.map +1 -1
  75. package/dist/tools/list.js +3 -7
  76. package/dist/tools/list.js.map +1 -1
  77. package/dist/tools/move.d.ts.map +1 -1
  78. package/dist/tools/move.js +2 -4
  79. package/dist/tools/move.js.map +1 -1
  80. package/dist/tools/progress.d.ts +1 -1
  81. package/dist/tools/progress.d.ts.map +1 -1
  82. package/dist/tools/progress.js.map +1 -1
  83. package/dist/tools/read.d.ts.map +1 -1
  84. package/dist/tools/read.js +36 -42
  85. package/dist/tools/read.js.map +1 -1
  86. package/dist/tools/replace-in-files.d.ts.map +1 -1
  87. package/dist/tools/replace-in-files.js +25 -42
  88. package/dist/tools/replace-in-files.js.map +1 -1
  89. package/dist/tools/search-content.d.ts.map +1 -1
  90. package/dist/tools/search-content.js +3 -25
  91. package/dist/tools/search-content.js.map +1 -1
  92. package/dist/tools/stat.d.ts.map +1 -1
  93. package/dist/tools/stat.js +9 -37
  94. package/dist/tools/stat.js.map +1 -1
  95. package/dist/transport/http-policy.d.ts +18 -15
  96. package/dist/transport/http-policy.d.ts.map +1 -1
  97. package/dist/transport/http-policy.js +29 -39
  98. package/dist/transport/http-policy.js.map +1 -1
  99. package/dist/transport/http.d.ts.map +1 -1
  100. package/dist/transport/http.js +29 -39
  101. package/dist/transport/http.js.map +1 -1
  102. package/package.json +4 -7
@@ -1 +1 @@
1
- {"version":3,"file":"path-completer.js","sourceRoot":"","sources":["../../src/core/path-completer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAOtC,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,sEAAsE;AAEtE,SAAS,oBAAoB,CAAC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YAClE,OAAO,sBAAsB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACxF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gBAAgB,CAAC,KAAK,CAAC,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,wDAAwD,EAAE;gBACpE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC/E,CAAC,CAAC;YACH,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF","sourcesContent":["import { opendir, stat } from 'node:fs/promises';\nimport { basename, dirname, isAbsolute, join, parse, resolve, sep } from 'node:path';\n\nimport { isNodeError, isNotFoundErrno, rethrowIfAborted } from './errors.js';\nimport { Logger } from './observability.js';\nimport { isPathWithinDirectories, isSamePath, normalizePath } from './path-utils.js';\nimport type { PathGuard } from './path.js';\nimport { resolveRealPath } from './path.js';\nimport { isSlash, toPosixPath } from './primitives.js';\n\nconst MAX_COMPLETION_ITEMS = 100;\nconst COMPLETION_RATE_LIMIT_MS = 100;\nconst MAX_COMPLETION_CACHE_KEYS = 128;\n\ninterface CacheEntry {\n ms: number;\n result: string[];\n}\n\n// ─── pure path-completion helpers (no instance state) ───────────────────────\n// Formerly static methods on PathCompleter. They take `allowed` explicitly and\n// touch no state, so they read as plain functions rather than a class used as\n// a namespace. PathCompleter keeps only the cache and the path guard.\n\nfunction hasTrailingSeparator(value: string): boolean {\n return value.length > 0 && isSlash(value.charCodeAt(value.length - 1));\n}\n\nfunction resolveFromBase(\n base: string,\n rawValue: string,\n trailingSeparator: boolean,\n): { searchDir: string; prefix: string } {\n const normalizedValue = normalizePath(resolve(base, rawValue));\n if (trailingSeparator) return { searchDir: normalizedValue, prefix: '' };\n return {\n searchDir: dirname(normalizedValue),\n prefix: basename(normalizedValue),\n };\n}\n\nfunction parseNamedRootInput(value: string): { rootName: string; remainder: string } | undefined {\n const normalizedInput = toPosixPath(value);\n if (!normalizedInput) return undefined;\n const slashIndex = normalizedInput.indexOf('/');\n if (slashIndex === -1) return { rootName: normalizedInput, remainder: '' };\n const rootName = normalizedInput.slice(0, slashIndex);\n if (!rootName) return undefined;\n return { rootName, remainder: normalizedInput.slice(slashIndex + 1) };\n}\n\nfunction findAllowedRootByName(rootName: string, allowed: readonly string[]): string | undefined {\n const normalizedRootName = rootName.toLowerCase();\n return allowed.find((candidate) => basename(candidate).toLowerCase() === normalizedRootName);\n}\n\nfunction resolveNamedRootContext(\n currentValue: string,\n allowed: readonly string[],\n): { searchDir: string; prefix: string } | undefined {\n const parsed = parseNamedRootInput(currentValue);\n if (!parsed) return undefined;\n const root = findAllowedRootByName(parsed.rootName, allowed);\n if (!root) return undefined;\n const trailingSeparator = hasTrailingSeparator(currentValue);\n return resolveFromBase(root, parsed.remainder, trailingSeparator);\n}\n\nasync function isAllowedCompletionDirectory(\n path: string,\n allowed: readonly string[],\n): Promise<boolean> {\n if (!isPathWithinDirectories(path, allowed)) return false;\n try {\n const stats = await stat(path);\n if (!stats.isDirectory()) return false;\n const real = await resolveRealPath(path);\n return real !== null && isPathWithinDirectories(real, allowed);\n } catch (err) {\n if (!isNotFoundErrno(err) && (!isNodeError(err) || err.code !== 'EACCES')) {\n Logger.debug('isAllowedCompletionDirectory: unexpected probe error', {\n path,\n error: String(err),\n });\n }\n return false;\n }\n}\n\nfunction withDirectorySeparator(value: string): string {\n return value.endsWith(sep) ? value : `${value}${sep}`;\n}\n\nfunction collectAllowedRoots(\n allowed: readonly string[],\n predicate: (root: string) => boolean,\n): string[] {\n const matches: string[] = [];\n for (const root of allowed) {\n if (predicate(root)) matches.push(withDirectorySeparator(root));\n }\n return matches;\n}\n\nfunction findRootPrefixMatches(currentValue: string, allowed: readonly string[]): string[] {\n const rootPrefix = parseNamedRootInput(currentValue)?.rootName.toLowerCase() ?? '';\n if (!rootPrefix) return collectAllowedRoots(allowed, () => true);\n return collectAllowedRoots(allowed, (root) =>\n basename(root).toLowerCase().startsWith(rootPrefix),\n );\n}\n\nfunction findMatchingRoots(\n searchDir: string,\n prefix: string,\n allowed: readonly string[],\n): string[] {\n const lowerPrefix = prefix.toLowerCase();\n const normalizedSearchDir = normalizePath(searchDir);\n return collectAllowedRoots(allowed, (root) => {\n const rootDir = dirname(root);\n if (!isSamePath(rootDir, normalizedSearchDir)) return false;\n return basename(root).toLowerCase().startsWith(lowerPrefix);\n });\n}\n\nfunction sortCompletionMatches(matches: string[]): void {\n const sepCode = sep.charCodeAt(0);\n matches.sort((left, right) => {\n const leftIsDir = left.charCodeAt(left.length - 1) === sepCode;\n const rightIsDir = right.charCodeAt(right.length - 1) === sepCode;\n if (leftIsDir && !rightIsDir) return -1;\n if (!leftIsDir && rightIsDir) return 1;\n return left.localeCompare(right);\n });\n}\n\nfunction mergeCompletionMatches(...matchGroups: readonly (readonly string[])[]): string[] {\n const uniqueMatches = new Set<string>();\n for (const group of matchGroups) {\n for (const match of group) uniqueMatches.add(match);\n }\n const merged = Array.from(uniqueMatches);\n sortCompletionMatches(merged);\n return merged;\n}\n\nasync function findMatchesInDirectory(\n searchDir: string,\n prefix: string,\n allowed: readonly string[],\n isSensitive?: (path: string) => boolean,\n): Promise<string[]> {\n const matches: string[] = [];\n if (!(await isAllowedCompletionDirectory(searchDir, allowed))) return matches;\n try {\n // Stream via opendir and collect every match; the MAX_COMPLETION_ITEMS\n // cap is applied AFTER the alphabetical sort in mergeCompletionMatches\n // (slice at the call site). Capping here would keep the opendir-first\n // 100, not the alphabetically-first 100 — the sort would only reorder\n // an already-arbitrary subset.\n const dir = await opendir(searchDir);\n try {\n const lowerPrefix = prefix.toLowerCase();\n for await (const entry of dir) {\n if (prefix !== '' && !entry.name.toLowerCase().startsWith(lowerPrefix)) continue;\n const fullPath = join(searchDir, entry.name);\n if (isSensitive?.(fullPath)) continue;\n matches.push(entry.isDirectory() ? `${fullPath}${sep}` : fullPath);\n }\n } finally {\n await dir.close().catch(() => {\n /* dir already closed or opendir never resolved */\n });\n }\n } catch (err) {\n if (!isNodeError(err) || (err.code !== 'ENOENT' && err.code !== 'EACCES')) {\n Logger.warn('PathCompleter.findMatchesInDirectory: readdir failed', {\n searchDir,\n error: String(err),\n });\n }\n }\n return matches;\n}\n\nfunction getSearchContext(\n currentValue: string,\n allowed: readonly string[],\n): { searchDir: string; prefix: string } | undefined {\n const trailingSeparator = hasTrailingSeparator(currentValue);\n if (isAbsolute(currentValue)) {\n return resolveFromBase(parse(currentValue).root || sep, currentValue, trailingSeparator);\n }\n const namedRootContext = resolveNamedRootContext(currentValue, allowed);\n if (namedRootContext) return namedRootContext;\n if (allowed.length === 1) {\n const base = allowed[0];\n if (base) return resolveFromBase(base, currentValue, trailingSeparator);\n }\n return undefined;\n}\n\n// ─── PathCompleter: cache + path guard ───────────────────────────────────────\n\nexport class PathCompleter {\n private cache = new Map<string, CacheEntry>();\n private readonly pathGuard: PathGuard;\n\n constructor(pathGuard: PathGuard) {\n this.pathGuard = pathGuard;\n }\n\n async suggest(value: string): Promise<string[]> {\n const now = Date.now();\n const cacheEntry = this.cache.get(value);\n\n if (cacheEntry && now - cacheEntry.ms < COMPLETION_RATE_LIMIT_MS) {\n return cacheEntry.result;\n }\n\n const results = await this.completePath(value);\n this.setCacheValue(value, { ms: now, result: results });\n return results;\n }\n\n private setCacheValue(key: string, entry: CacheEntry): void {\n // Entries are stale after COMPLETION_RATE_LIMIT_MS anyway, so the cap only\n // has to bound memory — dropping the whole map beats per-key LRU eviction.\n if (this.cache.size >= MAX_COMPLETION_CACHE_KEYS) this.cache.clear();\n this.cache.set(key, entry);\n }\n\n private async completePath(value: string): Promise<string[]> {\n const allowed = this.pathGuard.getAllowedDirectories();\n\n try {\n if (!value) {\n return allowed.slice(0, MAX_COMPLETION_ITEMS);\n }\n\n const context = getSearchContext(value, allowed);\n if (!context) {\n return findRootPrefixMatches(value, allowed).slice(0, MAX_COMPLETION_ITEMS);\n }\n\n const { searchDir, prefix } = context;\n const dirMatches = await findMatchesInDirectory(\n searchDir,\n prefix,\n allowed,\n this.pathGuard.isSensitive.bind(this.pathGuard),\n );\n const rootMatches = findMatchingRoots(searchDir, prefix, allowed);\n return mergeCompletionMatches(dirMatches, rootMatches).slice(0, MAX_COMPLETION_ITEMS);\n } catch (error) {\n rethrowIfAborted(error);\n Logger.warn('PathCompleter: completion failed, returning empty list', {\n error: error instanceof Error ? (error.stack ?? error.message) : String(error),\n });\n return [];\n }\n }\n}\n"]}
1
+ {"version":3,"file":"path-completer.js","sourceRoot":"","sources":["../../src/core/path-completer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAOtC,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,sEAAsE;AAEtE,SAAS,oBAAoB,CAAC,KAAa;IACzC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,UAA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,OAAO,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACjD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;YAC9E,CAAC;YAED,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;YACtC,MAAM,UAAU,GAAG,MAAM,sBAAsB,CAC7C,SAAS,EACT,MAAM,EACN,OAAO,EACP,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAChD,CAAC;YACF,MAAM,WAAW,GAAG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAClE,OAAO,sBAAsB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACxF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gBAAgB,CAAC,KAAK,CAAC,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,wDAAwD,EAAE;gBACpE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC/E,CAAC,CAAC;YACH,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF","sourcesContent":["import { opendir, stat } from 'node:fs/promises';\nimport { basename, dirname, isAbsolute, join, parse, resolve, sep } from 'node:path';\n\nimport { isNodeError, isNotFoundErrno, rethrowIfAborted } from './errors.js';\nimport { Logger } from './observability.js';\nimport { isPathWithinDirectories, isSamePath, normalizePath } from './path-utils.js';\nimport type { PathGuard } from './path.js';\nimport { resolveRealPath } from './path.js';\nimport { isSlash, toPosixPath } from './primitives.js';\n\nconst MAX_COMPLETION_ITEMS = 100;\nconst COMPLETION_RATE_LIMIT_MS = 100;\nconst MAX_COMPLETION_CACHE_KEYS = 128;\n\ninterface CacheEntry {\n ms: number;\n result: string[];\n}\n\n// ─── pure path-completion helpers (no instance state) ───────────────────────\n// Formerly static methods on PathCompleter. They take `allowed` explicitly and\n// touch no state, so they read as plain functions rather than a class used as\n// a namespace. PathCompleter keeps only the cache and the path guard.\n\nfunction hasTrailingSeparator(value: string): boolean {\n return value.length > 0 && isSlash(value.charCodeAt(value.length - 1));\n}\n\nfunction resolveFromBase(\n base: string,\n rawValue: string,\n trailingSeparator: boolean,\n): { searchDir: string; prefix: string } {\n const normalizedValue = normalizePath(resolve(base, rawValue));\n if (trailingSeparator) return { searchDir: normalizedValue, prefix: '' };\n return {\n searchDir: dirname(normalizedValue),\n prefix: basename(normalizedValue),\n };\n}\n\nfunction parseNamedRootInput(value: string): { rootName: string; remainder: string } | undefined {\n const normalizedInput = toPosixPath(value);\n if (!normalizedInput) return undefined;\n const slashIndex = normalizedInput.indexOf('/');\n if (slashIndex === -1) return { rootName: normalizedInput, remainder: '' };\n const rootName = normalizedInput.slice(0, slashIndex);\n if (!rootName) return undefined;\n return { rootName, remainder: normalizedInput.slice(slashIndex + 1) };\n}\n\nfunction findAllowedRootByName(rootName: string, allowed: readonly string[]): string | undefined {\n const normalizedRootName = rootName.toLowerCase();\n return allowed.find((candidate) => basename(candidate).toLowerCase() === normalizedRootName);\n}\n\nfunction resolveNamedRootContext(\n currentValue: string,\n allowed: readonly string[],\n): { searchDir: string; prefix: string } | undefined {\n const parsed = parseNamedRootInput(currentValue);\n if (!parsed) return undefined;\n const root = findAllowedRootByName(parsed.rootName, allowed);\n if (!root) return undefined;\n const trailingSeparator = hasTrailingSeparator(currentValue);\n return resolveFromBase(root, parsed.remainder, trailingSeparator);\n}\n\nasync function isAllowedCompletionDirectory(\n path: string,\n allowed: readonly string[],\n): Promise<boolean> {\n if (!isPathWithinDirectories(path, allowed)) return false;\n try {\n const stats = await stat(path);\n if (!stats.isDirectory()) return false;\n const real = await resolveRealPath(path);\n return real !== null && isPathWithinDirectories(real, allowed);\n } catch (err) {\n if (!isNotFoundErrno(err) && (!isNodeError(err) || err.code !== 'EACCES')) {\n Logger.debug('isAllowedCompletionDirectory: unexpected probe error', {\n path,\n error: String(err),\n });\n }\n return false;\n }\n}\n\nfunction withDirectorySeparator(value: string): string {\n return value.endsWith(sep) ? value : `${value}${sep}`;\n}\n\nfunction collectAllowedRoots(\n allowed: readonly string[],\n predicate: (root: string) => boolean,\n): string[] {\n return allowed.filter(predicate).map(withDirectorySeparator);\n}\n\nfunction findRootPrefixMatches(currentValue: string, allowed: readonly string[]): string[] {\n const rootPrefix = parseNamedRootInput(currentValue)?.rootName.toLowerCase() ?? '';\n if (!rootPrefix) return collectAllowedRoots(allowed, () => true);\n return collectAllowedRoots(allowed, (root) =>\n basename(root).toLowerCase().startsWith(rootPrefix),\n );\n}\n\nfunction findMatchingRoots(\n searchDir: string,\n prefix: string,\n allowed: readonly string[],\n): string[] {\n const lowerPrefix = prefix.toLowerCase();\n const normalizedSearchDir = normalizePath(searchDir);\n return collectAllowedRoots(allowed, (root) => {\n const rootDir = dirname(root);\n if (!isSamePath(rootDir, normalizedSearchDir)) return false;\n return basename(root).toLowerCase().startsWith(lowerPrefix);\n });\n}\n\nfunction mergeCompletionMatches(\n dirMatches: readonly string[],\n rootMatches: readonly string[],\n): string[] {\n const isDir = (v: string): boolean => v.endsWith(sep);\n return [...new Set([...dirMatches, ...rootMatches])].sort(\n (left, right) => Number(isDir(right)) - Number(isDir(left)) || left.localeCompare(right),\n );\n}\n\nasync function findMatchesInDirectory(\n searchDir: string,\n prefix: string,\n allowed: readonly string[],\n isSensitive?: (path: string) => boolean,\n): Promise<string[]> {\n const matches: string[] = [];\n if (!(await isAllowedCompletionDirectory(searchDir, allowed))) return matches;\n try {\n // Stream via opendir and collect every match; the MAX_COMPLETION_ITEMS\n // cap is applied AFTER the alphabetical sort in mergeCompletionMatches\n // (slice at the call site). Capping here would keep the opendir-first\n // 100, not the alphabetically-first 100 — the sort would only reorder\n // an already-arbitrary subset.\n const dir = await opendir(searchDir);\n try {\n const lowerPrefix = prefix.toLowerCase();\n for await (const entry of dir) {\n if (prefix !== '' && !entry.name.toLowerCase().startsWith(lowerPrefix)) continue;\n const fullPath = join(searchDir, entry.name);\n if (isSensitive?.(fullPath)) continue;\n matches.push(entry.isDirectory() ? `${fullPath}${sep}` : fullPath);\n }\n } finally {\n await dir.close().catch(() => {\n /* dir already closed or opendir never resolved */\n });\n }\n } catch (err) {\n if (!isNodeError(err) || (err.code !== 'ENOENT' && err.code !== 'EACCES')) {\n Logger.warn('PathCompleter.findMatchesInDirectory: readdir failed', {\n searchDir,\n error: String(err),\n });\n }\n }\n return matches;\n}\n\nfunction getSearchContext(\n currentValue: string,\n allowed: readonly string[],\n): { searchDir: string; prefix: string } | undefined {\n const trailingSeparator = hasTrailingSeparator(currentValue);\n if (isAbsolute(currentValue)) {\n return resolveFromBase(parse(currentValue).root || sep, currentValue, trailingSeparator);\n }\n const namedRootContext = resolveNamedRootContext(currentValue, allowed);\n if (namedRootContext) return namedRootContext;\n if (allowed.length === 1) {\n const base = allowed[0];\n if (base) return resolveFromBase(base, currentValue, trailingSeparator);\n }\n return undefined;\n}\n\n// ─── PathCompleter: cache + path guard ───────────────────────────────────────\n\nexport class PathCompleter {\n private cache = new Map<string, CacheEntry>();\n private readonly pathGuard: PathGuard;\n\n constructor(pathGuard: PathGuard) {\n this.pathGuard = pathGuard;\n }\n\n async suggest(value: string): Promise<string[]> {\n const now = Date.now();\n const cacheEntry = this.cache.get(value);\n\n if (cacheEntry && now - cacheEntry.ms < COMPLETION_RATE_LIMIT_MS) {\n return cacheEntry.result;\n }\n\n const results = await this.completePath(value);\n this.setCacheValue(value, { ms: now, result: results });\n return results;\n }\n\n private setCacheValue(key: string, entry: CacheEntry): void {\n // Entries are stale after COMPLETION_RATE_LIMIT_MS anyway, so the cap only\n // has to bound memory — dropping the whole map beats per-key LRU eviction.\n if (this.cache.size >= MAX_COMPLETION_CACHE_KEYS) this.cache.clear();\n this.cache.set(key, entry);\n }\n\n private async completePath(value: string): Promise<string[]> {\n const allowed = this.pathGuard.getAllowedDirectories();\n\n try {\n if (!value) {\n return allowed.slice(0, MAX_COMPLETION_ITEMS);\n }\n\n const context = getSearchContext(value, allowed);\n if (!context) {\n return findRootPrefixMatches(value, allowed).slice(0, MAX_COMPLETION_ITEMS);\n }\n\n const { searchDir, prefix } = context;\n const dirMatches = await findMatchesInDirectory(\n searchDir,\n prefix,\n allowed,\n this.pathGuard.isSensitive.bind(this.pathGuard),\n );\n const rootMatches = findMatchingRoots(searchDir, prefix, allowed);\n return mergeCompletionMatches(dirMatches, rootMatches).slice(0, MAX_COMPLETION_ITEMS);\n } catch (error) {\n rethrowIfAborted(error);\n Logger.warn('PathCompleter: completion failed, returning empty list', {\n error: error instanceof Error ? (error.stack ?? error.message) : String(error),\n });\n return [];\n }\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  export declare function getReservedDeviceNameForPath(requestedPath: string): string | undefined;
2
2
  export declare function isWindowsDriveRelativePath(requestedPath: string): boolean;
3
3
  export declare function normalizePath(p: string): string;
4
- export declare const IS_CASE_INSENSITIVE_FS: boolean;
4
+ export declare function normalizeCaseForComparison(value: string): string;
5
5
  export declare function isSamePath(left: string, right: string): boolean;
6
6
  export declare function normalizeAllowedDirectory(dir: string): string;
7
7
  export declare function isPathInsideDirectory(normalizedDirectory: string, normalizedCandidate: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../src/core/path-utils.ts"],"names":[],"mappings":"AAwCA,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAStF;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAkBzE;AAUD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa/C;AAED,eAAO,MAAM,sBAAsB,SAAwC,CAAC;AAM5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO/D;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAa7D;AAED,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,MAAM,EAC3B,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAST;AAED,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,SAAS,MAAM,EAAE,GAC7B,OAAO,CAET"}
1
+ {"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../src/core/path-utils.ts"],"names":[],"mappings":"AAwCA,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAStF;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAkBzE;AAUD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa/C;AAID,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAO/D;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAa7D;AAED,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,MAAM,EAC3B,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAST;AAED,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,SAAS,MAAM,EAAE,GAC7B,OAAO,CAET"}
@@ -80,8 +80,8 @@ export function normalizePath(p) {
80
80
  }
81
81
  return resolved;
82
82
  }
83
- export const IS_CASE_INSENSITIVE_FS = IS_WINDOWS || platform() === 'darwin';
84
- function normalizeCaseForComparison(value) {
83
+ const IS_CASE_INSENSITIVE_FS = IS_WINDOWS || platform() === 'darwin';
84
+ export function normalizeCaseForComparison(value) {
85
85
  return IS_CASE_INSENSITIVE_FS ? value.toLowerCase() : value;
86
86
  }
87
87
  export function isSamePath(left, right) {
@@ -1 +1 @@
1
- {"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../../src/core/path-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;AAE1B,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS;IAC5C,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;CACP,CAAC,CAAC;AAEH,SAAS,qBAAqB,CAAC,OAAe;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACnE,OAAO,qBAAqB,CAAC,GA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c,CAAC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import { homedir, platform } from 'node:os';\nimport { join, parse, resolve, sep } from 'node:path';\n\nimport { IS_WINDOWS, isAlpha, isSlash } from './primitives.js';\n\nconst CHAR_COLON = 58;\nconst HOMEDIR = homedir();\n\nconst RESERVED_DEVICE_NAMES = new Set<string>([\n 'CON',\n 'PRN',\n 'AUX',\n 'NUL',\n 'COM1',\n 'COM2',\n 'COM3',\n 'COM4',\n 'COM5',\n 'COM6',\n 'COM7',\n 'COM8',\n 'COM9',\n 'LPT1',\n 'LPT2',\n 'LPT3',\n 'LPT4',\n 'LPT5',\n 'LPT6',\n 'LPT7',\n 'LPT8',\n 'LPT9',\n]);\n\nfunction getReservedDeviceName(segment: string): string | undefined {\n const trimmed = segment.replace(/[. ]+$/, '');\n const withoutStream = trimmed.split(':')[0] ?? '';\n const baseName = (withoutStream.split('.')[0] ?? '').toUpperCase();\n return RESERVED_DEVICE_NAMES.has(baseName) ? baseName : undefined;\n}\n\nexport function getReservedDeviceNameForPath(requestedPath: string): string | undefined {\n const segments = requestedPath.split(/[\\\\/]/u);\n for (const segment of segments) {\n const reserved = getReservedDeviceName(segment);\n if (reserved) {\n return reserved;\n }\n }\n return undefined;\n}\n\nexport function isWindowsDriveRelativePath(requestedPath: string): boolean {\n // Check on all platforms so cross-platform clients cannot smuggle drive-relative\n // inputs (e.g. C:relative) to a POSIX-hosted server where path.resolve would\n // silently expand them relative to CWD.\n if (requestedPath.length < 2) {\n return false;\n }\n if (requestedPath.charCodeAt(1) !== CHAR_COLON) {\n return false;\n }\n if (!isAlpha(requestedPath.charCodeAt(0))) {\n return false;\n }\n\n if (requestedPath.length === 2) {\n return true;\n }\n return !isSlash(requestedPath.charCodeAt(2));\n}\n\nfunction expandHome(filepath: string): string {\n if (filepath === '~' || filepath.startsWith('~/') || filepath.startsWith('~\\\\')) {\n const rest = filepath.slice(1).replace(/^[/\\\\]+/, '');\n return rest ? join(HOMEDIR, rest) : HOMEDIR;\n }\n return filepath;\n}\n\nexport function normalizePath(p: string): string {\n const resolved = resolve(expandHome(p));\n\n // On Windows only the drive letter is lowercased (e.g. \"C:\\Foo\\Bar\").\n // The rest of the path retains its original casing.\n // IMPORTANT: callers must use isSamePath / isPathInsideDirectory for all\n // equality and containment checks — never raw string equality — because\n // those helpers apply full case-folding before comparing.\n if (IS_WINDOWS && resolved.length >= 2 && resolved.charCodeAt(1) === CHAR_COLON) {\n return resolved.charAt(0).toLowerCase() + resolved.slice(1);\n }\n\n return resolved;\n}\n\nexport const IS_CASE_INSENSITIVE_FS = IS_WINDOWS || platform() === 'darwin';\n\nfunction normalizeCaseForComparison(value: string): string {\n return IS_CASE_INSENSITIVE_FS ? value.toLowerCase() : value;\n}\n\nexport function isSamePath(left: string, right: string): boolean {\n if (left === right) {\n return true;\n }\n const leftResolved = normalizeCaseForComparison(resolve(left));\n const rightResolved = normalizeCaseForComparison(resolve(right));\n return leftResolved === rightResolved;\n}\n\nexport function normalizeAllowedDirectory(dir: string): string {\n const trimmed = dir.trim();\n if (trimmed.length === 0) return '';\n\n const normalized = normalizePath(trimmed);\n const { root } = parse(normalized);\n\n // Keep filesystem roots as-is (\"/\", \"c:\\\\\", \"\\\\\\\\server\\\\share\\\\\").\n if (isSamePath(normalized, root)) {\n return root;\n }\n\n return normalized.length > 1 && normalized.endsWith(sep) ? normalized.slice(0, -1) : normalized;\n}\n\nexport function isPathInsideDirectory(\n normalizedDirectory: string,\n normalizedCandidate: string,\n): boolean {\n const root = normalizeCaseForComparison(normalizedDirectory);\n const candidate = normalizeCaseForComparison(normalizedCandidate);\n\n if (root === candidate) return true;\n if (!candidate.startsWith(root)) return false;\n\n if (isSlash(root.charCodeAt(root.length - 1))) return true;\n return isSlash(candidate.charCodeAt(root.length));\n}\n\nexport function isPathWithinDirectories(\n normalizedPath: string,\n allowedDirs: readonly string[],\n): boolean {\n return allowedDirs.some((dir) => isPathInsideDirectory(dir, normalizedPath));\n}\n"]}
1
+ {"version":3,"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,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAEnC,oEAAoE;IACpE,IAAI,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AAClG,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,mBAA2B,EAC3B,mBAA2B;IAE3B,MAAM,IAAI,GAAG,0BAA0B,CAAC,mBAAmB,CAAC,CAAC;IAC7D,MAAM,SAAS,GAAG,0BAA0B,CAAC,mBAAmB,CAAC,CAAC;IAElE,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAE9C,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,OAAO,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,cAAsB,EACtB,WAA8B;IAE9B,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import { homedir, platform } from 'node:os';\nimport { join, parse, resolve, sep } from 'node:path';\n\nimport { IS_WINDOWS, isAlpha, isSlash } from './primitives.js';\n\nconst CHAR_COLON = 58;\nconst HOMEDIR = homedir();\n\nconst RESERVED_DEVICE_NAMES = new Set<string>([\n 'CON',\n 'PRN',\n 'AUX',\n 'NUL',\n 'COM1',\n 'COM2',\n 'COM3',\n 'COM4',\n 'COM5',\n 'COM6',\n 'COM7',\n 'COM8',\n 'COM9',\n 'LPT1',\n 'LPT2',\n 'LPT3',\n 'LPT4',\n 'LPT5',\n 'LPT6',\n 'LPT7',\n 'LPT8',\n 'LPT9',\n]);\n\nfunction getReservedDeviceName(segment: string): string | undefined {\n const trimmed = segment.replace(/[. ]+$/, '');\n const withoutStream = trimmed.split(':')[0] ?? '';\n const baseName = (withoutStream.split('.')[0] ?? '').toUpperCase();\n return RESERVED_DEVICE_NAMES.has(baseName) ? baseName : undefined;\n}\n\nexport function getReservedDeviceNameForPath(requestedPath: string): string | undefined {\n const segments = requestedPath.split(/[\\\\/]/u);\n for (const segment of segments) {\n const reserved = getReservedDeviceName(segment);\n if (reserved) {\n return reserved;\n }\n }\n return undefined;\n}\n\nexport function isWindowsDriveRelativePath(requestedPath: string): boolean {\n // Check on all platforms so cross-platform clients cannot smuggle drive-relative\n // inputs (e.g. C:relative) to a POSIX-hosted server where path.resolve would\n // silently expand them relative to CWD.\n if (requestedPath.length < 2) {\n return false;\n }\n if (requestedPath.charCodeAt(1) !== CHAR_COLON) {\n return false;\n }\n if (!isAlpha(requestedPath.charCodeAt(0))) {\n return false;\n }\n\n if (requestedPath.length === 2) {\n return true;\n }\n return !isSlash(requestedPath.charCodeAt(2));\n}\n\nfunction expandHome(filepath: string): string {\n if (filepath === '~' || filepath.startsWith('~/') || filepath.startsWith('~\\\\')) {\n const rest = filepath.slice(1).replace(/^[/\\\\]+/, '');\n return rest ? join(HOMEDIR, rest) : HOMEDIR;\n }\n return filepath;\n}\n\nexport function normalizePath(p: string): string {\n const resolved = resolve(expandHome(p));\n\n // On Windows only the drive letter is lowercased (e.g. \"C:\\Foo\\Bar\").\n // The rest of the path retains its original casing.\n // IMPORTANT: callers must use isSamePath / isPathInsideDirectory for all\n // equality and containment checks — never raw string equality — because\n // those helpers apply full case-folding before comparing.\n if (IS_WINDOWS && resolved.length >= 2 && resolved.charCodeAt(1) === CHAR_COLON) {\n return resolved.charAt(0).toLowerCase() + resolved.slice(1);\n }\n\n return resolved;\n}\n\nconst IS_CASE_INSENSITIVE_FS = IS_WINDOWS || platform() === 'darwin';\n\nexport function normalizeCaseForComparison(value: string): string {\n return IS_CASE_INSENSITIVE_FS ? value.toLowerCase() : value;\n}\n\nexport function isSamePath(left: string, right: string): boolean {\n if (left === right) {\n return true;\n }\n const leftResolved = normalizeCaseForComparison(resolve(left));\n const rightResolved = normalizeCaseForComparison(resolve(right));\n return leftResolved === rightResolved;\n}\n\nexport function normalizeAllowedDirectory(dir: string): string {\n const trimmed = dir.trim();\n if (trimmed.length === 0) return '';\n\n const normalized = normalizePath(trimmed);\n const { root } = parse(normalized);\n\n // Keep filesystem roots as-is (\"/\", \"c:\\\\\", \"\\\\\\\\server\\\\share\\\\\").\n if (isSamePath(normalized, root)) {\n return root;\n }\n\n return normalized.length > 1 && normalized.endsWith(sep) ? normalized.slice(0, -1) : normalized;\n}\n\nexport function isPathInsideDirectory(\n normalizedDirectory: string,\n normalizedCandidate: string,\n): boolean {\n const root = normalizeCaseForComparison(normalizedDirectory);\n const candidate = normalizeCaseForComparison(normalizedCandidate);\n\n if (root === candidate) return true;\n if (!candidate.startsWith(root)) return false;\n\n if (isSlash(root.charCodeAt(root.length - 1))) return true;\n return isSlash(candidate.charCodeAt(root.length));\n}\n\nexport function isPathWithinDirectories(\n normalizedPath: string,\n allowedDirs: readonly string[],\n): boolean {\n return allowedDirs.some((dir) => isPathInsideDirectory(dir, normalizedPath));\n}\n"]}
@@ -76,16 +76,14 @@ export declare class PathGuard {
76
76
  */
77
77
  isEntryAccessible(entryPath: string): Promise<boolean>;
78
78
  validateExistingPath(requestedPath: string): Promise<ValidatedPath>;
79
- /** True when a normalized path equals its own filesystem root (`C:\`, `/`). */
80
- private isFilesystemRoot;
81
79
  /**
82
- * True when a grant must never admit `targetDir` — a bare filesystem root, or
83
- * an unsafe path (home, /etc, C:\Windows, ...). Checked on the lexical path
84
- * AND on the one it resolves to: `expandAllowedDirectories` pushes each root's
85
- * realpath into the allowed set, so a lexical-only check let a symlink or
86
- * junction aliasing $HOME/C:\Windows in under an innocuous name — and the
87
- * confirmation prompt showed the alias, not the target. A target that cannot
88
- * be resolved is judged lexically; it does not exist to escape into.
80
+ * True when a grant must never admit `targetDir` — an unsafe path (home,
81
+ * /etc, C:\Windows, ...). Checked on the lexical path AND on the one it
82
+ * resolves to: `resolveAllowedDirectoriesState` pushes each root's realpath
83
+ * into the allowed set, so a lexical-only check let a symlink or junction
84
+ * aliasing $HOME/C:\Windows in under an innocuous name — and the confirmation
85
+ * prompt showed the alias, not the target. A target that cannot be resolved
86
+ * is judged lexically; it does not exist to escape into.
89
87
  */
90
88
  private isUnsafeGrantTarget;
91
89
  /** Walk up from a blocked path to the closest existing ancestor directory. */
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/core/path.ts"],"names":[],"mappings":"AAoCA,OAAO,CAAC,MAAM,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAChD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAE7E,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA6CD,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEhE;AAMD,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,SA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MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAwCvC,gBAAgB;IAa9B,OAAO,CAAC,4BAA4B;IAepC,OAAO,CAAC,cAAc;YAqDR,mBAAmB;IA2C3B,4BAA4B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAmClF,yBAAyB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBvE,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM;IAwBxD,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO;IAW9C,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,iBAAiB;YAOX,8BAA8B;IAwDtC,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAoBnE,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAoEpE,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC;CAoDnD"}
package/dist/core/path.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { lstat, readlink, realpath, stat } from 'node:fs/promises';
2
2
  import { homedir } from 'node:os';
3
- import { basename, dirname, isAbsolute, join, parse, relative, resolve } from 'node:path';
4
- import { timedSignal, withAbort } from './concurrency.js';
3
+ import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
4
+ import { withAbort } from './concurrency.js';
5
5
  import { cli } from './config.js';
6
6
  import { ERRNO_MAP, ErrorCode, FsError, isFsError, isNodeError, isNotFoundErrno, rethrowIfAborted, SKIPPABLE_ERRNOS, SKIPPABLE_FS_CODES, } from './errors.js';
7
7
  import { Logger } from './observability.js';
@@ -11,7 +11,7 @@ import { parseTrueEnvFlag, toPosixPath } from './primitives.js';
11
11
  import { SensitiveMatcher } from './sensitive.js';
12
12
  import { ROOTS_TIMEOUT_MS } from './util.js';
13
13
  /** True when `normalizedRoot` really resolves inside `bounds` (FS_ROOT_BOUNDARY). */
14
- async function isRootWithin(normalizedRoot, bounds, label, signal) {
14
+ async function isRootWithin(normalizedRoot, bounds, signal) {
15
15
  try {
16
16
  signal?.throwIfAborted();
17
17
  const realPath = await withAbort(realpath(normalizedRoot), signal);
@@ -22,20 +22,17 @@ async function isRootWithin(normalizedRoot, bounds, label, signal) {
22
22
  if (isNotFoundErrno(error)) {
23
23
  return false;
24
24
  }
25
- Logger.warn(`${label}: realpath failed unexpectedly`, {
25
+ Logger.warn('grantBoundary: realpath failed unexpectedly', {
26
26
  root: normalizedRoot,
27
27
  error: String(error),
28
28
  });
29
29
  return false;
30
30
  }
31
31
  }
32
- async function filterRootsWithin(roots, bounds, label, signal) {
32
+ async function filterRootsWithin(roots, bounds, signal) {
33
33
  const normalizedBounds = normalizeAllowedDirectories(bounds);
34
34
  const normalizedRoots = roots.map(normalizePath);
35
- if (normalizedRoots.length === 0) {
36
- return [];
37
- }
38
- const results = await Promise.all(normalizedRoots.map((root) => isRootWithin(root, normalizedBounds, label, signal)));
35
+ const results = await Promise.all(normalizedRoots.map((root) => isRootWithin(root, normalizedBounds, signal)));
39
36
  return normalizedRoots.filter((_, i) => results[i]);
40
37
  }
41
38
  /** `path.relative` with forward slashes, so displayed paths match across platforms. */
@@ -72,25 +69,15 @@ export async function resolveRealPath(normalized, signal) {
72
69
  throw error;
73
70
  }
74
71
  }
75
- async function expandAllowedDirectories(primaryDirs, signal) {
76
- const realPaths = await Promise.all(primaryDirs.map((dir) => resolveRealPath(dir, signal)));
77
- const expanded = [];
78
- for (let i = 0; i < primaryDirs.length; i++) {
79
- const primary = primaryDirs[i];
80
- if (!primary) {
81
- continue;
82
- }
83
- expanded.push(primary);
84
- const real = realPaths[i];
85
- if (real && !isSamePath(real, primary)) {
86
- expanded.push(real);
87
- }
88
- }
89
- return [...new Set(expanded)];
90
- }
91
72
  export async function resolveAllowedDirectoriesState(dirs, signal) {
92
73
  const primary = normalizeAllowedDirectories(dirs);
93
- return expandAllowedDirectories(primary, signal);
74
+ const reals = await Promise.all(primary.map((dir) => resolveRealPath(dir, signal)));
75
+ return [
76
+ ...new Set(primary.flatMap((dir, i) => {
77
+ const real = reals[i];
78
+ return real && !isSamePath(real, dir) ? [dir, real] : [dir];
79
+ })),
80
+ ];
94
81
  }
95
82
  // ---------------------------------------------------------------------------
96
83
  // Windows helpers
@@ -193,23 +180,18 @@ export class PathGuard {
193
180
  const details = await this.validateExistingPathDetailed(requestedPath);
194
181
  return details.resolvedPath;
195
182
  }
196
- /** True when a normalized path equals its own filesystem root (`C:\`, `/`). */
197
- isFilesystemRoot(normalizedPath) {
198
- return isSamePath(normalizedPath, parse(normalizedPath).root);
199
- }
200
183
  /**
201
- * True when a grant must never admit `targetDir` — a bare filesystem root, or
202
- * an unsafe path (home, /etc, C:\Windows, ...). Checked on the lexical path
203
- * AND on the one it resolves to: `expandAllowedDirectories` pushes each root's
204
- * realpath into the allowed set, so a lexical-only check let a symlink or
205
- * junction aliasing $HOME/C:\Windows in under an innocuous name — and the
206
- * confirmation prompt showed the alias, not the target. A target that cannot
207
- * be resolved is judged lexically; it does not exist to escape into.
184
+ * True when a grant must never admit `targetDir` — an unsafe path (home,
185
+ * /etc, C:\Windows, ...). Checked on the lexical path AND on the one it
186
+ * resolves to: `resolveAllowedDirectoriesState` pushes each root's realpath
187
+ * into the allowed set, so a lexical-only check let a symlink or junction
188
+ * aliasing $HOME/C:\Windows in under an innocuous name — and the confirmation
189
+ * prompt showed the alias, not the target. A target that cannot be resolved
190
+ * is judged lexically; it does not exist to escape into.
208
191
  */
209
192
  async isUnsafeGrantTarget(targetDir) {
210
- const isRefused = (dir) => this.isFilesystemRoot(dir) || isUnsafeCwdPath(dir);
211
193
  const normalized = normalizePath(targetDir);
212
- if (isRefused(normalized))
194
+ if (isUnsafeCwdPath(normalized))
213
195
  return true;
214
196
  let resolved;
215
197
  try {
@@ -218,7 +200,7 @@ export class PathGuard {
218
200
  catch {
219
201
  return false;
220
202
  }
221
- return !isSamePath(resolved, normalized) && isRefused(resolved);
203
+ return !isSamePath(resolved, normalized) && isUnsafeCwdPath(resolved);
222
204
  }
223
205
  /** Walk up from a blocked path to the closest existing ancestor directory. */
224
206
  async resolveGrantTargetDir(blockedPath) {
@@ -618,11 +600,11 @@ export class PathGuard {
618
600
  }
619
601
  }
620
602
  const baseline = [...cliAllowedDirs, ...envAllowedDirs, ...allowCwdDirs];
621
- const signal = timedSignal(undefined, ROOTS_TIMEOUT_MS);
603
+ const signal = AbortSignal.timeout(ROOTS_TIMEOUT_MS);
622
604
  // FS_ROOT_BOUNDARY is the only filter grants answer to (see
623
605
  // `grantedDirectories`); without one they pass through as accepted.
624
606
  const grantsToInclude = boundaries.length > 0
625
- ? await filterRootsWithin(this.grantedDirectories, boundaries, 'grantBoundary', signal)
607
+ ? await filterRootsWithin(this.grantedDirectories, boundaries, signal)
626
608
  : this.grantedDirectories;
627
609
  const combined = [...baseline, ...grantsToInclude];
628
610
  const nextState = await resolveAllowedDirectoriesState(combined, signal);
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/core/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,SAAS,EACT,SAAS,EACT,OAAO,EACP,SAAS,EACT,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,M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AAI,CACT,SAAS,EACT,oEAAoE,GAAG,EAAE,CAC1E,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,CAAC,GAAG,cAAc,EAAE,GAAG,cAAc,EAAE,GAAG,YAAY,CAAC,CAAC;QAEzE,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;QACxD,4DAA4D;QAC5D,oEAAoE;QACpE,MAAM,eAAe,GACnB,UAAU,CAAC,MAAM,GAAG,CAAC;YACnB,CAAC,CAAC,MAAM,iBAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,CAAC;YACvF,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAE9B,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,eAAe,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,8BAA8B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzE,wEAAwE;QACxE,kEAAkE;QAClE,0BAA0B;QAC1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import type { Stats } from 'node:fs';\nimport { lstat, readlink, realpath, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, isAbsolute, join, parse, relative, resolve } from 'node:path';\n\nimport { timedSignal, withAbort } from './concurrency.js';\nimport { cli } from './config.js';\nimport {\n ERRNO_MAP,\n ErrorCode,\n FsError,\n isFsError,\n isNodeError,\n isNotFoundErrno,\n rethrowIfAborted,\n SKIPPABLE_ERRNOS,\n SKIPPABLE_FS_CODES,\n} from './errors.js';\nimport { Logger } from './observability.js';\nimport { findProjectRoot, isUnsafeCwdPath, resolveConfiguredDirs } from './path-discovery.js';\nimport {\n getReservedDeviceNameForPath,\n isPathWithinDirectories,\n isSamePath,\n isWindowsDriveRelativePath,\n normalizeAllowedDirectory,\n normalizePath,\n} from './path-utils.js';\nimport { parseTrueEnvFlag, toPosixPath } from './primitives.js';\nimport { SensitiveMatcher } from './sensitive.js';\nimport { ROOTS_TIMEOUT_MS } from './util.js';\n\n// Allowed-directory assembly and the PathGuard that enforces it. The\n// sensitive-file denylist lives in sensitive.ts, and the character-level\n// primitives (IS_WINDOWS, isAlpha, isSlash, toPosixPath) live in\n// primitives.ts.\ndeclare const ValidatedPathBrand: unique symbol;\nexport type ValidatedPath = string & { readonly [ValidatedPathBrand]: true };\n\nexport interface ValidatedPathDetails {\n requestedPath: string;\n resolvedPath: string;\n isSymlink: boolean;\n}\n\nexport interface ServerOptions {\n allowCwd?: boolean;\n cliAllowedDirs?: string[];\n readOnly?: boolean;\n}\n\n/** True when `normalizedRoot` really resolves inside `bounds` (FS_ROOT_BOUNDARY). */\nasync function isRootWithin(\n normalizedRoot: string,\n bounds: readonly string[],\n label: string,\n signal?: AbortSignal,\n): Promise<boolean> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalizedRoot), signal);\n return isPathWithinDirectories(normalizePath(realPath), bounds);\n } catch (error) {\n rethrowIfAborted(error);\n if (isNotFoundErrno(error)) {\n return false;\n }\n Logger.warn(`${label}: realpath failed unexpectedly`, {\n root: normalizedRoot,\n error: String(error),\n });\n return false;\n }\n}\n\nasync function filterRootsWithin(\n roots: readonly string[],\n bounds: readonly string[],\n label: string,\n signal?: AbortSignal,\n): Promise<string[]> {\n const normalizedBounds = normalizeAllowedDirectories(bounds);\n const normalizedRoots = roots.map(normalizePath);\n if (normalizedRoots.length === 0) {\n return [];\n }\n\n const results = await Promise.all(\n normalizedRoots.map((root) => isRootWithin(root, normalizedBounds, label, signal)),\n );\n\n return normalizedRoots.filter((_, i) => results[i]);\n}\n\n/** `path.relative` with forward slashes, so displayed paths match across platforms. */\nexport function toPosixRelative(from: string, to: string): string {\n return toPosixPath(relative(from, to));\n}\n\n// ---------------------------------------------------------------------------\n// Resolver pipeline\n// ---------------------------------------------------------------------------\n\nexport function normalizeAllowedDirectories(dirs: readonly string[]): string[] {\n const normalized: string[] = [];\n for (const dir of dirs) {\n const entry = normalizeAllowedDirectory(dir);\n if (entry.length > 0) {\n normalized.push(entry);\n }\n }\n return [...new Set(normalized)];\n}\n\nexport async function resolveRealPath(\n normalized: string,\n signal?: AbortSignal,\n): Promise<string | null> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalized), signal);\n return normalizeAllowedDirectory(realPath);\n } catch (error) {\n rethrowIfAborted(error);\n // Only suppress ENOENT — the path genuinely does not exist.\n // EACCES, EIO, and other unexpected errors are rethrown so callers\n // cannot silently operate with a narrowed allowed-directory set.\n if (isNotFoundErrno(error)) {\n return null;\n }\n throw error;\n }\n}\n\nasync function expandAllowedDirectories(\n primaryDirs: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const realPaths = await Promise.all(primaryDirs.map((dir) => resolveRealPath(dir, signal)));\n\n const expanded: string[] = [];\n for (let i = 0; i < primaryDirs.length; i++) {\n const primary = primaryDirs[i];\n if (!primary) {\n continue;\n }\n\n expanded.push(primary);\n\n const real = realPaths[i];\n if (real && !isSamePath(real, primary)) {\n expanded.push(real);\n }\n }\n\n return [...new Set(expanded)];\n}\n\nexport async function resolveAllowedDirectoriesState(\n dirs: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const primary = normalizeAllowedDirectories(dirs);\n return expandAllowedDirectories(primary, signal);\n}\n\n// ---------------------------------------------------------------------------\n// Windows helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Accepted risk: validation methods resolve/verify a path (symlinks, boundaries,\n * sensitivity) and then return a plain string; the actual fs operation happens\n * afterward as a separate syscall (classic TOCTOU). A symlink swapped in that\n * exact window could redirect the follow-up operation. This is mitigated by\n * re-validating the resolved real path (not just the requested path) and by\n * walking ancestors to catch escapes before the target exists, but it is not\n * eliminated — doing so would require fd-based operations (open with\n * O_NOFOLLOW / operate on the resolved fd) throughout core/fs.ts. Acceptable\n * tradeoff for a local, single-user filesystem server today.\n */\nexport class PathGuard {\n private allowedDirectoriesState: string[] | undefined;\n private readonly sensitive = new SensitiveMatcher();\n /**\n * Directories added by an accepted access grant (R8) — from the tool\n * executor's grant round-trip, or from a client's declared workspace roots on\n * the legacy stdio leg. Held separately from the configured baseline because\n * `recomputeAllowedDirectories` rebuilds that baseline from CLI args and env\n * on every call: anything merged into it would be recomputed away.\n *\n * These are NOT filtered against the baseline. A granted directory is\n * out-of-baseline by definition, so a baseline filter dropped every one while\n * `applyGrant` still reported success — the whole round-trip prompted the\n * user and then changed nothing. FS_ROOT_BOUNDARY and the unsafe-path denylist\n * remain the limits, both checked in `applyGrant` — the only writer of this\n * field — so the recompute can rebuild from it without re-filtering.\n */\n private grantedDirectories: string[] = [];\n private rootBoundaries: string[] = [];\n\n // ponytail: one mutex per PathGuard. If per-session grant throughput ever\n // matters, split into per-grant-dir locks; a single lock is correct for the\n // stdio + InMemoryEventStore single-process model.\n #mutex = Promise.resolve();\n\n private readonly options: ServerOptions | undefined;\n\n constructor(options?: ServerOptions) {\n this.options = options;\n }\n\n initialize(expanded: readonly string[]): void {\n this.allowedDirectoriesState = normalizeAllowedDirectories(expanded);\n }\n\n isInitialized(): boolean {\n return this.allowedDirectoriesState !== undefined;\n }\n\n /**\n * Run `fn` as the next holder of the guard's single mutation lock. Every\n * change to the allowed set goes through this so concurrent grants cannot\n * interleave their read-`await`-write and lose a grant (GRANT-1).\n */\n private async runExclusive<T>(fn: () => Promise<T>): Promise<T> {\n const result = this.#mutex.then(fn, fn);\n this.#mutex = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n }\n\n getAllowedDirectories(): string[] {\n if (!this.allowedDirectoriesState) {\n return [];\n }\n return [...this.allowedDirectoriesState];\n }\n\n isSensitive(filePath: string): boolean {\n return this.sensitive.isSensitive(filePath);\n }\n\n /**\n * True when `entryPath` is both within the guard's allowed directories and\n * not sensitive, checking the requested AND resolved paths. EVERY entry is\n * realpath-resolved via validateExistingPathDetailed: a symlinked ancestor\n * directory pointing outside the sandbox would otherwise pass the lexical\n * containment check (fs.glob follows symlinks and yields external entries as\n * non-symlink dirents). validateExistingPathDetailed re-checks containment on\n * the real path against this.allowedDirectoriesState (the guard's full\n * allowed set — a superset of the single-root `bounds` callers pass) and\n * re-checks sensitivity on the resolved target, throwing ACCESS_DENIED for\n * escapes/sensitive, which the catch below turns into a filter. Skippable\n * errno/fs errors return false (the entry is filtered, not fatal). The\n * accepted TOCTOU window is documented at the class docstring above.\n */\n async isEntryAccessible(entryPath: string): Promise<boolean> {\n const isSensitive = (requestedPath: string, resolvedPath: string): boolean =>\n this.isSensitive(requestedPath) || this.isSensitive(resolvedPath);\n try {\n const validated = await this.validateExistingPathDetailed(entryPath);\n return !isSensitive(validated.requestedPath, validated.resolvedPath);\n } catch (error) {\n if (isFsError(error)) {\n if (SKIPPABLE_FS_CODES.has(error.code)) return false;\n throw error;\n }\n if (isNodeError(error) && error.code !== undefined && SKIPPABLE_ERRNOS.has(error.code))\n return false;\n throw error;\n }\n }\n\n async validateExistingPath(requestedPath: string): Promise<ValidatedPath> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n return details.resolvedPath as ValidatedPath;\n }\n\n /** True when a normalized path equals its own filesystem root (`C:\\`, `/`). */\n private isFilesystemRoot(normalizedPath: string): boolean {\n return isSamePath(normalizedPath, parse(normalizedPath).root);\n }\n\n /**\n * True when a grant must never admit `targetDir` — a bare filesystem root, or\n * an unsafe path (home, /etc, C:\\Windows, ...). Checked on the lexical path\n * AND on the one it resolves to: `expandAllowedDirectories` pushes each root's\n * realpath into the allowed set, so a lexical-only check let a symlink or\n * junction aliasing $HOME/C:\\Windows in under an innocuous name — and the\n * confirmation prompt showed the alias, not the target. A target that cannot\n * be resolved is judged lexically; it does not exist to escape into.\n */\n private async isUnsafeGrantTarget(targetDir: string): Promise<boolean> {\n const isRefused = (dir: string): boolean => this.isFilesystemRoot(dir) || isUnsafeCwdPath(dir);\n const normalized = normalizePath(targetDir);\n if (isRefused(normalized)) return true;\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(normalized));\n } catch {\n return false;\n }\n return !isSamePath(resolved, normalized) && isRefused(resolved);\n }\n\n /** Walk up from a blocked path to the closest existing ancestor directory. */\n private async resolveGrantTargetDir(blockedPath: string): Promise<string> {\n let targetDir = blockedPath;\n for (;;) {\n const parent = dirname(targetDir);\n try {\n // An existing directory is the grant target; an existing file grants\n // its parent directory.\n return (await stat(targetDir)).isDirectory() ? targetDir : parent;\n } catch {\n // Missing — keep walking up.\n }\n if (parent === targetDir) return targetDir;\n targetDir = parent;\n }\n }\n\n /**\n * Pre-check (no mutation, no callback): given the paths a tool is about to\n * operate on, return the sorted, de-duplicated grant-target directories for\n * those that are outside the allowed roots AND grantable (within FS_ROOT_BOUNDARY\n * when it is configured). A path whose nearest existing ancestor escapes the\n * boundary is NOT grantable and is omitted — the operation will fail with\n * ACCESS_DENIED for it rather than prompt. The caller returns an\n * `input_required` result carrying exactly this set (R7), and on retry applies\n * each accepted grant via {@link applyGrant} (R8). `requestState` binds this\n * set so a grant accepted for X cannot authorize Y (R9).\n */\n async precheckAccess(paths: readonly string[]): Promise<string[]> {\n if (!this.allowedDirectoriesState || paths.length === 0) {\n return [];\n }\n const allowedDirs = this.allowedDirectoriesState;\n const grantDirs: string[] = [];\n for (const requested of paths) {\n if (!requested) {\n continue;\n }\n const normalized = normalizePath(requested);\n if (isPathWithinDirectories(normalized, allowedDirs)) {\n continue;\n }\n const targetDir = normalizePath(await this.resolveGrantTargetDir(normalized));\n // Never offer a grant into a bare filesystem root or an unsafe path (home,\n // /etc, C:\\Windows, ...). Without FS_ROOT_BOUNDARY, isWithinBoundary returns\n // true for everything, so this is the one guard that still rejects roots a\n // misleading grant could reach. Mirrors the check gating --allow-cwd.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n continue;\n }\n if (grantDirs.includes(targetDir)) {\n continue;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n continue;\n }\n grantDirs.push(targetDir);\n }\n return grantDirs.sort();\n }\n\n /**\n * Apply an accepted access grant: enforce FS_ROOT_BOUNDARY again (a TOCTOU\n * re-check against the boundary resolved at config time), then extend the\n * allowed roots for the remainder of the session (R8, A4). Returns false when\n * the boundary or the unsafe-path denylist blocks the grant, AND when the\n * recompute did not actually admit the directory — the return value now\n * reports what the guard's allowed set really holds, not merely that the\n * pre-checks passed. The caller leaves a refused path to fail with\n * ACCESS_DENIED during the operation. Idempotent: re-granting an already\n * allowed directory is a no-op via the dedup in `initialize`.\n */\n async applyGrant(targetDir: string): Promise<boolean> {\n // Defense-in-depth: even a tampered/accepted grant cannot extend roots into\n // an unsafe path. The precheckAccess guard already refuses to offer these;\n // this catches a grant that arrived by another route — the legacy stdio\n // `roots/list` seeding, which has no confirmation round-trip at all.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n return false;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n return false;\n }\n // Read + write under the mutation lock so a concurrent grant cannot\n // interleave and lose this grant (GRANT-1). runExclusive is not reentrant:\n // nothing in this body may take the lock again.\n return this.runExclusive(async () => {\n const previous = this.grantedDirectories;\n this.grantedDirectories = [...previous, normalizePath(targetDir)];\n try {\n await this.recomputeAllowedDirectories();\n } catch (error) {\n // A failed recompute leaves the guard with its previous, consistent view.\n this.grantedDirectories = previous;\n throw error;\n }\n // Verify rather than assume: a boundary that no longer covers this\n // directory would drop it in the recompute above, and reporting success\n // for a grant that did not land is exactly the failure this replaces.\n if (isPathWithinDirectories(normalizePath(targetDir), this.getAllowedDirectories())) {\n return true;\n }\n this.grantedDirectories = previous;\n await this.recomputeAllowedDirectories();\n return false;\n });\n }\n\n // The guard already realpath-resolved FS_ROOT_BOUNDARY into rootBoundaries\n // during recomputeAllowedDirectories. Reuse that single source of truth so\n // grant paths check the same boundary the rest of the guard enforces,\n // instead of re-reading the env and re-resolving each entry.\n private async isWithinBoundary(targetDir: string): Promise<boolean> {\n if (this.rootBoundaries.length === 0) {\n return true;\n }\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(targetDir));\n } catch {\n resolved = normalizePath(targetDir);\n }\n return isPathWithinDirectories(resolved, this.rootBoundaries);\n }\n\n private validateAccessAndSensitivity(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n const result = this.validateAccess(requestedPath);\n this.assertNotSensitiveFile(requestedPath, requestedPath);\n this.assertNotSensitiveFile(result.normalizedRequested, requestedPath);\n return result;\n }\n\n // Synchronous since the access-grant round-trip moved to the executor's\n // pre-check: validateAccess only does lexical containment math and throws,\n // no async I/O remains. Callers still `await` it for uniform control-flow;\n // awaiting a non-thenable returns it unchanged.\n private validateAccess(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n if (!this.allowedDirectoriesState) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'PathGuard not initialized. Call initialize() first.',\n requestedPath,\n );\n }\n if (isWindowsDriveRelativePath(requestedPath)) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Drive-relative paths are not allowed. Use C:\\\\path or C:/path instead of C:path.',\n requestedPath,\n );\n }\n const reservedDevice = getReservedDeviceNameForPath(requestedPath);\n if (reservedDevice) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n `Reserved Windows device name not allowed: ${reservedDevice}.`,\n requestedPath,\n );\n }\n\n const normalizedRequested = normalizePath(requestedPath);\n const allowedDirs = this.allowedDirectoriesState;\n\n const accessDeniedHint =\n allowedDirs.length > 0\n ? `Allowed: ${allowedDirs.join(', ')}`\n : 'No allowed directories configured.';\n\n if (!isPathWithinDirectories(normalizedRequested, allowedDirs)) {\n // Out of root. The access-grant `input_required` round-trip is driven by\n // the executor's pre-check (precheckAccess) BEFORE the operation runs, so\n // by the time validation reaches here any grantable out-of-root path has\n // already been accepted and added to the allowed set. A path still out of\n // root here was either declined, ungrantable (outside FS_ROOT_BOUNDARY), or\n // never pre-checked — fail closed.\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n return {\n normalizedRequested,\n allowedDirs: this.allowedDirectoriesState,\n accessDeniedHint,\n };\n }\n\n private async handleRealpathError(\n error: unknown,\n normalizedRequested: string,\n allowedDirs: string[],\n accessDeniedHint: string,\n requestedPath: string,\n ): Promise<never> {\n if (isNotFoundErrno(error)) {\n // Resolve the nearest existing ancestor to detect out-of-sandbox symlinks.\n // e.g. if `link -> C:\\external` and path is `link\\nonexistent.txt`, the\n // ancestor resolves outside allowed dirs → ACCESS_DENIED, not NOT_FOUND.\n try {\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n } catch (ancestorErr) {\n // Rethrow any FsError — collapsing e.g. UNKNOWN to NOT_FOUND would mask\n // incomplete sandbox checks and make bugs invisible to callers.\n if (isFsError(ancestorErr)) {\n throw ancestorErr;\n }\n }\n\n throw new FsError(ErrorCode.NOT_FOUND, 'Path not found', requestedPath, error);\n }\n\n const mapped =\n isNodeError(error) && error.code !== undefined ? ERRNO_MAP[error.code] : undefined;\n throw new FsError(\n mapped ?? ErrorCode.UNKNOWN,\n 'Cannot access path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n async validateExistingPathDetailed(requestedPath: string): Promise<ValidatedPathDetails> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n let realPath: string;\n try {\n realPath = await realpath(normalizedRequested);\n } catch (error) {\n realPath = await this.handleRealpathError(\n error,\n normalizedRequested,\n allowedDirs,\n accessDeniedHint,\n requestedPath,\n );\n }\n\n const normalizedReal = normalizePath(realPath);\n\n if (!isPathWithinDirectories(normalizedReal, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Re-check the resolved real path: a symlink inside an allowed root may\n // point at a sensitive file (e.g. link -> .env). The early check above only\n // sees the requested/normalized path, not the symlink target.\n this.assertNotSensitiveFile(normalizedReal, requestedPath);\n\n return {\n requestedPath: normalizedRequested,\n resolvedPath: normalizedReal,\n isSymlink: !isSamePath(normalizedRequested, normalizedReal),\n };\n }\n\n async validateExistingDirectory(requestedPath: string): Promise<string> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n\n let stats: Stats;\n try {\n stats = await stat(details.resolvedPath);\n } catch (error) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot access directory',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n if (!stats.isDirectory()) {\n throw new FsError(ErrorCode.NOT_DIRECTORY, 'Not a directory', requestedPath);\n }\n\n return details.resolvedPath;\n }\n\n resolvePathOrRoot(pathValue: string | undefined): string {\n if (pathValue && pathValue.trim().length > 0) {\n return pathValue;\n }\n const roots = this.getAllowedDirectories();\n if (roots.length === 0) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'No roots configured. Use the roots tool or --allow-cwd.',\n );\n }\n if (roots.length > 1) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Multiple roots configured. Provide an explicit path.',\n );\n }\n const root = roots[0];\n if (!root) {\n throw new FsError(ErrorCode.ACCESS_DENIED, 'Workspace root is unexpectedly undefined');\n }\n return root;\n }\n\n isAllowedRoot(normalizedPath: string): boolean {\n // isSamePath case-folds on case-insensitive filesystems (win + darwin),\n // matching the containment checks used everywhere else in the guard. The\n // previous IS_WINDOWS-only fold left darwin doing exact-case compares here\n // while isPathInsideDirectory folded — a root matched case-insensitively\n // everywhere else was missed.\n return this.getAllowedDirectories().some((dir) => isSamePath(dir, normalizedPath));\n }\n\n // Checks ONLY the sensitive-file denylist. Root containment and symlink\n // resolution must be verified separately (e.g. via validateExistingPath).\n private assertNotSensitiveFile(checkPath: string, requestedPath: string): void {\n if (this.isSensitive(checkPath)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Sensitive file blocked. Set ALLOW_SENSITIVE=1 to override.',\n requestedPath,\n );\n }\n }\n\n private throwAccessDenied(requestedPath: string, hint?: string): never {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n hint ? `Outside allowed directories. ${hint}` : 'Outside allowed directories.',\n requestedPath,\n );\n }\n private async resolveNearestExistingAncestor(\n requestedPath: string,\n currentPath: string,\n ): Promise<{ realAncestor: string; resolvedTarget: string }> {\n const missingSegments: string[] = [];\n let current = currentPath;\n for (;;) {\n try {\n const realAncestor = normalizePath(await realpath(current));\n const resolvedTarget =\n missingSegments.length === 0\n ? realAncestor\n : normalizePath(join(realAncestor, ...missingSegments.reverse()));\n return { realAncestor, resolvedTarget };\n } catch (error) {\n try {\n const stats = await lstat(current);\n if (stats.isSymbolicLink()) {\n const target = await readlink(current);\n const resolvedTarget = isAbsolute(target) ? target : resolve(dirname(current), target);\n const normalizedTarget = normalizePath(resolvedTarget);\n const allowedDirs = this.getAllowedDirectories();\n if (!isPathWithinDirectories(normalizedTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath);\n }\n }\n } catch (lstatErr) {\n if (isFsError(lstatErr) && lstatErr.code === ErrorCode.ACCESS_DENIED) {\n throw lstatErr;\n }\n // ENOENT is expected during ancestor walk — the entry simply doesn't exist.\n // Any other error (EACCES, EIO, ELOOP) is unexpected; fail safe.\n if (!isNodeError(lstatErr) || lstatErr.code !== 'ENOENT') {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot probe symlink ancestor',\n requestedPath,\n lstatErr instanceof Error ? lstatErr : undefined,\n );\n }\n }\n const parent = dirname(current);\n if (parent === current) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot resolve path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n missingSegments.push(basename(current));\n current = parent;\n }\n }\n }\n\n async validatePathForWrite(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n // Re-check the resolved target: a symlink inside an allowed root may point\n // at a sensitive file. Writing through such a link must be blocked too.\n this.assertNotSensitiveFile(resolvedTarget, requestedPath);\n return resolvedTarget as ValidatedPath;\n }\n\n async validatePathForDelete(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n // A workspace root is refused here, before the parent-containment check\n // below reaches for a parent that is out-of-root by construction and\n // reports \"Outside allowed directories\" for the one directory the caller\n // can see IS allowed. delete-file.ts keeps its own root check for the\n // nested-root case, where the parent is itself an allowed root and this\n // path is never taken.\n if (this.isAllowedRoot(normalizedRequested)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Deleting a workspace root directory is not allowed',\n requestedPath,\n );\n }\n\n const parent = dirname(normalizedRequested);\n let realParent: string;\n try {\n realParent = await realpath(parent);\n } catch (error) {\n throw new FsError(\n ErrorCode.NOT_FOUND,\n 'Parent directory not found',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n const normalizedRealParent = normalizePath(realParent);\n\n if (!isPathWithinDirectories(normalizedRealParent, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Resolve the final component when it exists. For deletion, we ONLY\n // block if the real target is outside the sandbox IF the target is\n // NOT a symlink. Deleting a symlink is safe even if it points outside.\n try {\n const stats = await lstat(normalizedRequested);\n if (stats.isSymbolicLink()) {\n // Symlink: check link sensitivity but don't resolve target.\n // The parent check above ensures the link itself is in an allowed root.\n this.assertNotSensitiveFile(normalizedRequested, requestedPath);\n return normalizedRequested as ValidatedPath;\n }\n\n // Not a symlink: resolve to catch path escapes (e.g. /allowed/dir/../../etc)\n // and block sensitive files.\n const realTarget = normalizePath(await realpath(normalizedRequested));\n if (!isPathWithinDirectories(realTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n this.assertNotSensitiveFile(realTarget, requestedPath);\n return realTarget as ValidatedPath;\n } catch (error) {\n // A denial raised inside this block (out-of-root real target, or a\n // sensitive file reached through a symlinked parent) must propagate.\n // Only a probe failure — ENOENT and friends — falls through to the\n // parent check, which is sufficient for a path that does not exist.\n if (isFsError(error)) {\n throw error;\n }\n }\n return normalizedRequested as ValidatedPath;\n }\n\n async recomputeAllowedDirectories(): Promise<void> {\n const cliAllowedDirs = normalizeAllowedDirectories(this.options?.cliAllowedDirs ?? []);\n\n // Parse allowed directories from environment variable\n const allowMissing =\n cli.allowMissingRoots ??\n parseTrueEnvFlag(process.env['FS_ALLOW_MISSING_ROOTS'], 'FS_ALLOW_MISSING_ROOTS');\n const envAllowedDirs = await resolveConfiguredDirs('FS_ALLOWED_DIRS', { allowMissing });\n\n // Parse FS_ROOT_BOUNDARY (the --root-boundary flag beats the env var)\n const boundaries = await resolveConfiguredDirs('FS_ROOT_BOUNDARY', {\n resolveReal: true,\n ...(cli.rootBoundary !== undefined ? { rawValue: cli.rootBoundary } : {}),\n });\n\n const allowCwd = Boolean(this.options?.allowCwd);\n const allowCwdDirs: string[] = [];\n if (allowCwd) {\n let cwd = normalizePath(process.cwd());\n const walkCwd =\n cli.allowCwdWalk ?? parseTrueEnvFlag(process.env['FS_ALLOW_CWD_WALK'], 'FS_ALLOW_CWD_WALK');\n if (walkCwd) {\n cwd = await findProjectRoot(cwd, [...boundaries, homedir()]);\n }\n if (isUnsafeCwdPath(cwd)) {\n Logger.emit(\n 'warning',\n `Skipped adding unsafe current working directory to allowed list: ${cwd}`,\n );\n } else {\n allowCwdDirs.push(cwd);\n }\n }\n\n const baseline = [...cliAllowedDirs, ...envAllowedDirs, ...allowCwdDirs];\n\n const signal = timedSignal(undefined, ROOTS_TIMEOUT_MS);\n // FS_ROOT_BOUNDARY is the only filter grants answer to (see\n // `grantedDirectories`); without one they pass through as accepted.\n const grantsToInclude =\n boundaries.length > 0\n ? await filterRootsWithin(this.grantedDirectories, boundaries, 'grantBoundary', signal)\n : this.grantedDirectories;\n\n const combined = [...baseline, ...grantsToInclude];\n const nextState = await resolveAllowedDirectoriesState(combined, signal);\n // Commit boundaries and the allowed set together, after every await has\n // resolved, so a rejecting recompute leaves the guard's previous,\n // consistent view intact.\n this.rootBoundaries = boundaries;\n this.initialize(nextState);\n }\n}\n"]}
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/core/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,SAAS,EACT,SAAS,EACT,OAAO,EACP,SAAS,EACT,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,UAAU,EACV,0BAA0B,EAC1B,yB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AgB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,CAAC;YAC9F,IAAI,OAAO,EAAE,CAAC;gBACZ,GAAG,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,CAAC,GAAG,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YAC/D,CAAC;YACD,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,MAAM,CAAC,IAAI,CACT,SAAS,EACT,oEAAoE,GAAG,EAAE,CAC1E,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,CAAC,GAAG,cAAc,EAAE,GAAG,cAAc,EAAE,GAAG,YAAY,CAAC,CAAC;QAEzE,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACrD,4DAA4D;QAC5D,oEAAoE;QACpE,MAAM,eAAe,GACnB,UAAU,CAAC,MAAM,GAAG,CAAC;YACnB,CAAC,CAAC,MAAM,iBAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,EAAE,MAAM,CAAC;YACtE,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAE9B,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,eAAe,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,8BAA8B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzE,wEAAwE;QACxE,kEAAkE;QAClE,0BAA0B;QAC1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import type { Stats } from 'node:fs';\nimport { lstat, readlink, realpath, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';\n\nimport { withAbort } from './concurrency.js';\nimport { cli } from './config.js';\nimport {\n ERRNO_MAP,\n ErrorCode,\n FsError,\n isFsError,\n isNodeError,\n isNotFoundErrno,\n rethrowIfAborted,\n SKIPPABLE_ERRNOS,\n SKIPPABLE_FS_CODES,\n} from './errors.js';\nimport { Logger } from './observability.js';\nimport { findProjectRoot, isUnsafeCwdPath, resolveConfiguredDirs } from './path-discovery.js';\nimport {\n getReservedDeviceNameForPath,\n isPathWithinDirectories,\n isSamePath,\n isWindowsDriveRelativePath,\n normalizeAllowedDirectory,\n normalizePath,\n} from './path-utils.js';\nimport { parseTrueEnvFlag, toPosixPath } from './primitives.js';\nimport { SensitiveMatcher } from './sensitive.js';\nimport { ROOTS_TIMEOUT_MS } from './util.js';\n\n// Allowed-directory assembly and the PathGuard that enforces it. The\n// sensitive-file denylist lives in sensitive.ts, and the character-level\n// primitives (IS_WINDOWS, isAlpha, isSlash, toPosixPath) live in\n// primitives.ts.\ndeclare const ValidatedPathBrand: unique symbol;\nexport type ValidatedPath = string & { readonly [ValidatedPathBrand]: true };\n\nexport interface ValidatedPathDetails {\n requestedPath: string;\n resolvedPath: string;\n isSymlink: boolean;\n}\n\nexport interface ServerOptions {\n allowCwd?: boolean;\n cliAllowedDirs?: string[];\n readOnly?: boolean;\n}\n\n/** True when `normalizedRoot` really resolves inside `bounds` (FS_ROOT_BOUNDARY). */\nasync function isRootWithin(\n normalizedRoot: string,\n bounds: readonly string[],\n signal?: AbortSignal,\n): Promise<boolean> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalizedRoot), signal);\n return isPathWithinDirectories(normalizePath(realPath), bounds);\n } catch (error) {\n rethrowIfAborted(error);\n if (isNotFoundErrno(error)) {\n return false;\n }\n Logger.warn('grantBoundary: realpath failed unexpectedly', {\n root: normalizedRoot,\n error: String(error),\n });\n return false;\n }\n}\n\nasync function filterRootsWithin(\n roots: readonly string[],\n bounds: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const normalizedBounds = normalizeAllowedDirectories(bounds);\n const normalizedRoots = roots.map(normalizePath);\n\n const results = await Promise.all(\n normalizedRoots.map((root) => isRootWithin(root, normalizedBounds, signal)),\n );\n\n return normalizedRoots.filter((_, i) => results[i]);\n}\n\n/** `path.relative` with forward slashes, so displayed paths match across platforms. */\nexport function toPosixRelative(from: string, to: string): string {\n return toPosixPath(relative(from, to));\n}\n\n// ---------------------------------------------------------------------------\n// Resolver pipeline\n// ---------------------------------------------------------------------------\n\nexport function normalizeAllowedDirectories(dirs: readonly string[]): string[] {\n const normalized: string[] = [];\n for (const dir of dirs) {\n const entry = normalizeAllowedDirectory(dir);\n if (entry.length > 0) {\n normalized.push(entry);\n }\n }\n return [...new Set(normalized)];\n}\n\nexport async function resolveRealPath(\n normalized: string,\n signal?: AbortSignal,\n): Promise<string | null> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalized), signal);\n return normalizeAllowedDirectory(realPath);\n } catch (error) {\n rethrowIfAborted(error);\n // Only suppress ENOENT — the path genuinely does not exist.\n // EACCES, EIO, and other unexpected errors are rethrown so callers\n // cannot silently operate with a narrowed allowed-directory set.\n if (isNotFoundErrno(error)) {\n return null;\n }\n throw error;\n }\n}\n\nexport async function resolveAllowedDirectoriesState(\n dirs: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const primary = normalizeAllowedDirectories(dirs);\n const reals = await Promise.all(primary.map((dir) => resolveRealPath(dir, signal)));\n return [\n ...new Set(\n primary.flatMap((dir, i) => {\n const real = reals[i];\n return real && !isSamePath(real, dir) ? [dir, real] : [dir];\n }),\n ),\n ];\n}\n\n// ---------------------------------------------------------------------------\n// Windows helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Accepted risk: validation methods resolve/verify a path (symlinks, boundaries,\n * sensitivity) and then return a plain string; the actual fs operation happens\n * afterward as a separate syscall (classic TOCTOU). A symlink swapped in that\n * exact window could redirect the follow-up operation. This is mitigated by\n * re-validating the resolved real path (not just the requested path) and by\n * walking ancestors to catch escapes before the target exists, but it is not\n * eliminated — doing so would require fd-based operations (open with\n * O_NOFOLLOW / operate on the resolved fd) throughout core/fs.ts. Acceptable\n * tradeoff for a local, single-user filesystem server today.\n */\nexport class PathGuard {\n private allowedDirectoriesState: string[] | undefined;\n private readonly sensitive = new SensitiveMatcher();\n /**\n * Directories added by an accepted access grant (R8) — from the tool\n * executor's grant round-trip, or from a client's declared workspace roots on\n * the legacy stdio leg. Held separately from the configured baseline because\n * `recomputeAllowedDirectories` rebuilds that baseline from CLI args and env\n * on every call: anything merged into it would be recomputed away.\n *\n * These are NOT filtered against the baseline. A granted directory is\n * out-of-baseline by definition, so a baseline filter dropped every one while\n * `applyGrant` still reported success — the whole round-trip prompted the\n * user and then changed nothing. FS_ROOT_BOUNDARY and the unsafe-path denylist\n * remain the limits, both checked in `applyGrant` — the only writer of this\n * field — so the recompute can rebuild from it without re-filtering.\n */\n private grantedDirectories: string[] = [];\n private rootBoundaries: string[] = [];\n\n // ponytail: one mutex per PathGuard. If per-session grant throughput ever\n // matters, split into per-grant-dir locks; a single lock is correct for the\n // stdio + InMemoryEventStore single-process model.\n #mutex = Promise.resolve();\n\n private readonly options: ServerOptions | undefined;\n\n constructor(options?: ServerOptions) {\n this.options = options;\n }\n\n initialize(expanded: readonly string[]): void {\n this.allowedDirectoriesState = normalizeAllowedDirectories(expanded);\n }\n\n isInitialized(): boolean {\n return this.allowedDirectoriesState !== undefined;\n }\n\n /**\n * Run `fn` as the next holder of the guard's single mutation lock. Every\n * change to the allowed set goes through this so concurrent grants cannot\n * interleave their read-`await`-write and lose a grant (GRANT-1).\n */\n private async runExclusive<T>(fn: () => Promise<T>): Promise<T> {\n const result = this.#mutex.then(fn, fn);\n this.#mutex = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n }\n\n getAllowedDirectories(): string[] {\n if (!this.allowedDirectoriesState) {\n return [];\n }\n return [...this.allowedDirectoriesState];\n }\n\n isSensitive(filePath: string): boolean {\n return this.sensitive.isSensitive(filePath);\n }\n\n /**\n * True when `entryPath` is both within the guard's allowed directories and\n * not sensitive, checking the requested AND resolved paths. EVERY entry is\n * realpath-resolved via validateExistingPathDetailed: a symlinked ancestor\n * directory pointing outside the sandbox would otherwise pass the lexical\n * containment check (fs.glob follows symlinks and yields external entries as\n * non-symlink dirents). validateExistingPathDetailed re-checks containment on\n * the real path against this.allowedDirectoriesState (the guard's full\n * allowed set — a superset of the single-root `bounds` callers pass) and\n * re-checks sensitivity on the resolved target, throwing ACCESS_DENIED for\n * escapes/sensitive, which the catch below turns into a filter. Skippable\n * errno/fs errors return false (the entry is filtered, not fatal). The\n * accepted TOCTOU window is documented at the class docstring above.\n */\n async isEntryAccessible(entryPath: string): Promise<boolean> {\n const isSensitive = (requestedPath: string, resolvedPath: string): boolean =>\n this.isSensitive(requestedPath) || this.isSensitive(resolvedPath);\n try {\n const validated = await this.validateExistingPathDetailed(entryPath);\n return !isSensitive(validated.requestedPath, validated.resolvedPath);\n } catch (error) {\n if (isFsError(error)) {\n if (SKIPPABLE_FS_CODES.has(error.code)) return false;\n throw error;\n }\n if (isNodeError(error) && error.code !== undefined && SKIPPABLE_ERRNOS.has(error.code))\n return false;\n throw error;\n }\n }\n\n async validateExistingPath(requestedPath: string): Promise<ValidatedPath> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n return details.resolvedPath as ValidatedPath;\n }\n\n /**\n * True when a grant must never admit `targetDir` — an unsafe path (home,\n * /etc, C:\\Windows, ...). Checked on the lexical path AND on the one it\n * resolves to: `resolveAllowedDirectoriesState` pushes each root's realpath\n * into the allowed set, so a lexical-only check let a symlink or junction\n * aliasing $HOME/C:\\Windows in under an innocuous name — and the confirmation\n * prompt showed the alias, not the target. A target that cannot be resolved\n * is judged lexically; it does not exist to escape into.\n */\n private async isUnsafeGrantTarget(targetDir: string): Promise<boolean> {\n const normalized = normalizePath(targetDir);\n if (isUnsafeCwdPath(normalized)) return true;\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(normalized));\n } catch {\n return false;\n }\n return !isSamePath(resolved, normalized) && isUnsafeCwdPath(resolved);\n }\n\n /** Walk up from a blocked path to the closest existing ancestor directory. */\n private async resolveGrantTargetDir(blockedPath: string): Promise<string> {\n let targetDir = blockedPath;\n for (;;) {\n const parent = dirname(targetDir);\n try {\n // An existing directory is the grant target; an existing file grants\n // its parent directory.\n return (await stat(targetDir)).isDirectory() ? targetDir : parent;\n } catch {\n // Missing — keep walking up.\n }\n if (parent === targetDir) return targetDir;\n targetDir = parent;\n }\n }\n\n /**\n * Pre-check (no mutation, no callback): given the paths a tool is about to\n * operate on, return the sorted, de-duplicated grant-target directories for\n * those that are outside the allowed roots AND grantable (within FS_ROOT_BOUNDARY\n * when it is configured). A path whose nearest existing ancestor escapes the\n * boundary is NOT grantable and is omitted — the operation will fail with\n * ACCESS_DENIED for it rather than prompt. The caller returns an\n * `input_required` result carrying exactly this set (R7), and on retry applies\n * each accepted grant via {@link applyGrant} (R8). `requestState` binds this\n * set so a grant accepted for X cannot authorize Y (R9).\n */\n async precheckAccess(paths: readonly string[]): Promise<string[]> {\n if (!this.allowedDirectoriesState || paths.length === 0) {\n return [];\n }\n const allowedDirs = this.allowedDirectoriesState;\n const grantDirs: string[] = [];\n for (const requested of paths) {\n if (!requested) {\n continue;\n }\n const normalized = normalizePath(requested);\n if (isPathWithinDirectories(normalized, allowedDirs)) {\n continue;\n }\n const targetDir = normalizePath(await this.resolveGrantTargetDir(normalized));\n // Never offer a grant into a bare filesystem root or an unsafe path (home,\n // /etc, C:\\Windows, ...). Without FS_ROOT_BOUNDARY, isWithinBoundary returns\n // true for everything, so this is the one guard that still rejects roots a\n // misleading grant could reach. Mirrors the check gating --allow-cwd.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n continue;\n }\n if (grantDirs.includes(targetDir)) {\n continue;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n continue;\n }\n grantDirs.push(targetDir);\n }\n return grantDirs.sort();\n }\n\n /**\n * Apply an accepted access grant: enforce FS_ROOT_BOUNDARY again (a TOCTOU\n * re-check against the boundary resolved at config time), then extend the\n * allowed roots for the remainder of the session (R8, A4). Returns false when\n * the boundary or the unsafe-path denylist blocks the grant, AND when the\n * recompute did not actually admit the directory — the return value now\n * reports what the guard's allowed set really holds, not merely that the\n * pre-checks passed. The caller leaves a refused path to fail with\n * ACCESS_DENIED during the operation. Idempotent: re-granting an already\n * allowed directory is a no-op via the dedup in `initialize`.\n */\n async applyGrant(targetDir: string): Promise<boolean> {\n // Defense-in-depth: even a tampered/accepted grant cannot extend roots into\n // an unsafe path. The precheckAccess guard already refuses to offer these;\n // this catches a grant that arrived by another route — the legacy stdio\n // `roots/list` seeding, which has no confirmation round-trip at all.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n return false;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n return false;\n }\n // Read + write under the mutation lock so a concurrent grant cannot\n // interleave and lose this grant (GRANT-1). runExclusive is not reentrant:\n // nothing in this body may take the lock again.\n return this.runExclusive(async () => {\n const previous = this.grantedDirectories;\n this.grantedDirectories = [...previous, normalizePath(targetDir)];\n try {\n await this.recomputeAllowedDirectories();\n } catch (error) {\n // A failed recompute leaves the guard with its previous, consistent view.\n this.grantedDirectories = previous;\n throw error;\n }\n // Verify rather than assume: a boundary that no longer covers this\n // directory would drop it in the recompute above, and reporting success\n // for a grant that did not land is exactly the failure this replaces.\n if (isPathWithinDirectories(normalizePath(targetDir), this.getAllowedDirectories())) {\n return true;\n }\n this.grantedDirectories = previous;\n await this.recomputeAllowedDirectories();\n return false;\n });\n }\n\n // The guard already realpath-resolved FS_ROOT_BOUNDARY into rootBoundaries\n // during recomputeAllowedDirectories. Reuse that single source of truth so\n // grant paths check the same boundary the rest of the guard enforces,\n // instead of re-reading the env and re-resolving each entry.\n private async isWithinBoundary(targetDir: string): Promise<boolean> {\n if (this.rootBoundaries.length === 0) {\n return true;\n }\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(targetDir));\n } catch {\n resolved = normalizePath(targetDir);\n }\n return isPathWithinDirectories(resolved, this.rootBoundaries);\n }\n\n private validateAccessAndSensitivity(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n const result = this.validateAccess(requestedPath);\n this.assertNotSensitiveFile(requestedPath, requestedPath);\n this.assertNotSensitiveFile(result.normalizedRequested, requestedPath);\n return result;\n }\n\n // Synchronous since the access-grant round-trip moved to the executor's\n // pre-check: validateAccess only does lexical containment math and throws,\n // no async I/O remains. Callers still `await` it for uniform control-flow;\n // awaiting a non-thenable returns it unchanged.\n private validateAccess(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n if (!this.allowedDirectoriesState) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'PathGuard not initialized. Call initialize() first.',\n requestedPath,\n );\n }\n if (isWindowsDriveRelativePath(requestedPath)) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Drive-relative paths are not allowed. Use C:\\\\path or C:/path instead of C:path.',\n requestedPath,\n );\n }\n const reservedDevice = getReservedDeviceNameForPath(requestedPath);\n if (reservedDevice) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n `Reserved Windows device name not allowed: ${reservedDevice}.`,\n requestedPath,\n );\n }\n\n const normalizedRequested = normalizePath(requestedPath);\n const allowedDirs = this.allowedDirectoriesState;\n\n const accessDeniedHint =\n allowedDirs.length > 0\n ? `Allowed: ${allowedDirs.join(', ')}`\n : 'No allowed directories configured.';\n\n if (!isPathWithinDirectories(normalizedRequested, allowedDirs)) {\n // Out of root. The access-grant `input_required` round-trip is driven by\n // the executor's pre-check (precheckAccess) BEFORE the operation runs, so\n // by the time validation reaches here any grantable out-of-root path has\n // already been accepted and added to the allowed set. A path still out of\n // root here was either declined, ungrantable (outside FS_ROOT_BOUNDARY), or\n // never pre-checked — fail closed.\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n return {\n normalizedRequested,\n allowedDirs: this.allowedDirectoriesState,\n accessDeniedHint,\n };\n }\n\n private async handleRealpathError(\n error: unknown,\n normalizedRequested: string,\n allowedDirs: string[],\n accessDeniedHint: string,\n requestedPath: string,\n ): Promise<never> {\n if (isNotFoundErrno(error)) {\n // Resolve the nearest existing ancestor to detect out-of-sandbox symlinks.\n // e.g. if `link -> C:\\external` and path is `link\\nonexistent.txt`, the\n // ancestor resolves outside allowed dirs → ACCESS_DENIED, not NOT_FOUND.\n try {\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n } catch (ancestorErr) {\n // Rethrow any FsError — collapsing e.g. UNKNOWN to NOT_FOUND would mask\n // incomplete sandbox checks and make bugs invisible to callers.\n if (isFsError(ancestorErr)) {\n throw ancestorErr;\n }\n }\n\n throw new FsError(ErrorCode.NOT_FOUND, 'Path not found', requestedPath, error);\n }\n\n const mapped =\n isNodeError(error) && error.code !== undefined ? ERRNO_MAP[error.code] : undefined;\n throw new FsError(\n mapped ?? ErrorCode.UNKNOWN,\n 'Cannot access path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n async validateExistingPathDetailed(requestedPath: string): Promise<ValidatedPathDetails> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n let realPath: string;\n try {\n realPath = await realpath(normalizedRequested);\n } catch (error) {\n realPath = await this.handleRealpathError(\n error,\n normalizedRequested,\n allowedDirs,\n accessDeniedHint,\n requestedPath,\n );\n }\n\n const normalizedReal = normalizePath(realPath);\n\n if (!isPathWithinDirectories(normalizedReal, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Re-check the resolved real path: a symlink inside an allowed root may\n // point at a sensitive file (e.g. link -> .env). The early check above only\n // sees the requested/normalized path, not the symlink target.\n this.assertNotSensitiveFile(normalizedReal, requestedPath);\n\n return {\n requestedPath: normalizedRequested,\n resolvedPath: normalizedReal,\n isSymlink: !isSamePath(normalizedRequested, normalizedReal),\n };\n }\n\n async validateExistingDirectory(requestedPath: string): Promise<string> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n\n let stats: Stats;\n try {\n stats = await stat(details.resolvedPath);\n } catch (error) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot access directory',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n if (!stats.isDirectory()) {\n throw new FsError(ErrorCode.NOT_DIRECTORY, 'Not a directory', requestedPath);\n }\n\n return details.resolvedPath;\n }\n\n resolvePathOrRoot(pathValue: string | undefined): string {\n if (pathValue && pathValue.trim().length > 0) {\n return pathValue;\n }\n const roots = this.getAllowedDirectories();\n if (roots.length === 0) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'No roots configured. Use the roots tool or --allow-cwd.',\n );\n }\n if (roots.length > 1) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Multiple roots configured. Provide an explicit path.',\n );\n }\n const root = roots[0];\n if (!root) {\n throw new FsError(ErrorCode.ACCESS_DENIED, 'Workspace root is unexpectedly undefined');\n }\n return root;\n }\n\n isAllowedRoot(normalizedPath: string): boolean {\n // isSamePath case-folds on case-insensitive filesystems (win + darwin),\n // matching the containment checks used everywhere else in the guard. The\n // previous IS_WINDOWS-only fold left darwin doing exact-case compares here\n // while isPathInsideDirectory folded — a root matched case-insensitively\n // everywhere else was missed.\n return this.getAllowedDirectories().some((dir) => isSamePath(dir, normalizedPath));\n }\n\n // Checks ONLY the sensitive-file denylist. Root containment and symlink\n // resolution must be verified separately (e.g. via validateExistingPath).\n private assertNotSensitiveFile(checkPath: string, requestedPath: string): void {\n if (this.isSensitive(checkPath)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Sensitive file blocked. Set ALLOW_SENSITIVE=1 to override.',\n requestedPath,\n );\n }\n }\n\n private throwAccessDenied(requestedPath: string, hint?: string): never {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n hint ? `Outside allowed directories. ${hint}` : 'Outside allowed directories.',\n requestedPath,\n );\n }\n private async resolveNearestExistingAncestor(\n requestedPath: string,\n currentPath: string,\n ): Promise<{ realAncestor: string; resolvedTarget: string }> {\n const missingSegments: string[] = [];\n let current = currentPath;\n for (;;) {\n try {\n const realAncestor = normalizePath(await realpath(current));\n const resolvedTarget =\n missingSegments.length === 0\n ? realAncestor\n : normalizePath(join(realAncestor, ...missingSegments.reverse()));\n return { realAncestor, resolvedTarget };\n } catch (error) {\n try {\n const stats = await lstat(current);\n if (stats.isSymbolicLink()) {\n const target = await readlink(current);\n const resolvedTarget = isAbsolute(target) ? target : resolve(dirname(current), target);\n const normalizedTarget = normalizePath(resolvedTarget);\n const allowedDirs = this.getAllowedDirectories();\n if (!isPathWithinDirectories(normalizedTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath);\n }\n }\n } catch (lstatErr) {\n if (isFsError(lstatErr) && lstatErr.code === ErrorCode.ACCESS_DENIED) {\n throw lstatErr;\n }\n // ENOENT is expected during ancestor walk — the entry simply doesn't exist.\n // Any other error (EACCES, EIO, ELOOP) is unexpected; fail safe.\n if (!isNodeError(lstatErr) || lstatErr.code !== 'ENOENT') {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot probe symlink ancestor',\n requestedPath,\n lstatErr instanceof Error ? lstatErr : undefined,\n );\n }\n }\n const parent = dirname(current);\n if (parent === current) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot resolve path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n missingSegments.push(basename(current));\n current = parent;\n }\n }\n }\n\n async validatePathForWrite(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n // Re-check the resolved target: a symlink inside an allowed root may point\n // at a sensitive file. Writing through such a link must be blocked too.\n this.assertNotSensitiveFile(resolvedTarget, requestedPath);\n return resolvedTarget as ValidatedPath;\n }\n\n async validatePathForDelete(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n // A workspace root is refused here, before the parent-containment check\n // below reaches for a parent that is out-of-root by construction and\n // reports \"Outside allowed directories\" for the one directory the caller\n // can see IS allowed. delete-file.ts keeps its own root check for the\n // nested-root case, where the parent is itself an allowed root and this\n // path is never taken.\n if (this.isAllowedRoot(normalizedRequested)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Deleting a workspace root directory is not allowed',\n requestedPath,\n );\n }\n\n const parent = dirname(normalizedRequested);\n let realParent: string;\n try {\n realParent = await realpath(parent);\n } catch (error) {\n throw new FsError(\n ErrorCode.NOT_FOUND,\n 'Parent directory not found',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n const normalizedRealParent = normalizePath(realParent);\n\n if (!isPathWithinDirectories(normalizedRealParent, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Resolve the final component when it exists. For deletion, we ONLY\n // block if the real target is outside the sandbox IF the target is\n // NOT a symlink. Deleting a symlink is safe even if it points outside.\n try {\n const stats = await lstat(normalizedRequested);\n if (stats.isSymbolicLink()) {\n // Symlink: check link sensitivity but don't resolve target.\n // The parent check above ensures the link itself is in an allowed root.\n this.assertNotSensitiveFile(normalizedRequested, requestedPath);\n return normalizedRequested as ValidatedPath;\n }\n\n // Not a symlink: resolve to catch path escapes (e.g. /allowed/dir/../../etc)\n // and block sensitive files.\n const realTarget = normalizePath(await realpath(normalizedRequested));\n if (!isPathWithinDirectories(realTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n this.assertNotSensitiveFile(realTarget, requestedPath);\n return realTarget as ValidatedPath;\n } catch (error) {\n // A denial raised inside this block (out-of-root real target, or a\n // sensitive file reached through a symlinked parent) must propagate.\n // Only a probe failure — ENOENT and friends — falls through to the\n // parent check, which is sufficient for a path that does not exist.\n if (isFsError(error)) {\n throw error;\n }\n }\n return normalizedRequested as ValidatedPath;\n }\n\n async recomputeAllowedDirectories(): Promise<void> {\n const cliAllowedDirs = normalizeAllowedDirectories(this.options?.cliAllowedDirs ?? []);\n\n // Parse allowed directories from environment variable\n const allowMissing =\n cli.allowMissingRoots ??\n parseTrueEnvFlag(process.env['FS_ALLOW_MISSING_ROOTS'], 'FS_ALLOW_MISSING_ROOTS');\n const envAllowedDirs = await resolveConfiguredDirs('FS_ALLOWED_DIRS', { allowMissing });\n\n // Parse FS_ROOT_BOUNDARY (the --root-boundary flag beats the env var)\n const boundaries = await resolveConfiguredDirs('FS_ROOT_BOUNDARY', {\n resolveReal: true,\n ...(cli.rootBoundary !== undefined ? { rawValue: cli.rootBoundary } : {}),\n });\n\n const allowCwd = Boolean(this.options?.allowCwd);\n const allowCwdDirs: string[] = [];\n if (allowCwd) {\n let cwd = normalizePath(process.cwd());\n const walkCwd =\n cli.allowCwdWalk ?? parseTrueEnvFlag(process.env['FS_ALLOW_CWD_WALK'], 'FS_ALLOW_CWD_WALK');\n if (walkCwd) {\n cwd = await findProjectRoot(cwd, [...boundaries, homedir()]);\n }\n if (isUnsafeCwdPath(cwd)) {\n Logger.emit(\n 'warning',\n `Skipped adding unsafe current working directory to allowed list: ${cwd}`,\n );\n } else {\n allowCwdDirs.push(cwd);\n }\n }\n\n const baseline = [...cliAllowedDirs, ...envAllowedDirs, ...allowCwdDirs];\n\n const signal = AbortSignal.timeout(ROOTS_TIMEOUT_MS);\n // FS_ROOT_BOUNDARY is the only filter grants answer to (see\n // `grantedDirectories`); without one they pass through as accepted.\n const grantsToInclude =\n boundaries.length > 0\n ? await filterRootsWithin(this.grantedDirectories, boundaries, signal)\n : this.grantedDirectories;\n\n const combined = [...baseline, ...grantsToInclude];\n const nextState = await resolveAllowedDirectoriesState(combined, signal);\n // Commit boundaries and the allowed set together, after every await has\n // resolved, so a rejecting recompute leaves the guard's previous,\n // consistent view intact.\n this.rootBoundaries = boundaries;\n this.initialize(nextState);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAwC,OAAO,EAAa,MAAM,aAAa,CAAC;AAqEvF,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEzE,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,cAAc,GACf,CAAC,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACnC,CAAC,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