MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / sensitiveDirectoryRefusal

Function sensitiveDirectoryRefusal

src/utils.ts:369–400  ·  view source on GitHub ↗
(dirPath: string)

Source from the content-addressed store, hash-verified

367 * can vet a path a project root is searched for from.
368 */
369export function sensitiveDirectoryRefusal(dirPath: string): string | null {
370 const resolved = path.resolve(dirPath);
371 const lexical = path.resolve(stripWin32NamespacePrefix(dirPath));
372 const real = nativeRealPath(lexical);
373 const candidates = [lexical];
374 if (real && real !== lexical) candidates.push(real);
375 const named = (candidate: string): string =>
376 candidate === resolved ? resolved : `${resolved} (resolves to ${candidate})`;
377
378 // Block sensitive system directories
379 const systemPaths = sensitiveSystemPaths();
380 for (const candidate of candidates) {
381 if (
382 SENSITIVE_PATHS.has(candidate) ||
383 SENSITIVE_PATHS.has(candidate.toLowerCase()) ||
384 systemPaths.has(foldPathCase(candidate))
385 ) {
386 return `Refusing to operate on sensitive system directory: ${named(candidate)}`;
387 }
388 }
389
390 // Also block common sensitive home subdirectories
391 const homeTrees = sensitiveHomeTrees();
392 for (const candidate of candidates) {
393 const folded = foldPathCase(candidate);
394 if (homeTrees.some((tree) => isSameOrUnder(folded, tree))) {
395 return `Refusing to operate on sensitive directory: ${named(candidate)}`;
396 }
397 }
398
399 return null;
400}
401
402/**
403 * Safely parse JSON with a fallback value.

Callers 2

resolveServerRootFunction · 0.90
validateProjectPathFunction · 0.85

Calls 10

nativeRealPathFunction · 0.85
sensitiveSystemPathsFunction · 0.85
foldPathCaseFunction · 0.85
sensitiveHomeTreesFunction · 0.85
isSameOrUnderFunction · 0.85
pushMethod · 0.80
hasMethod · 0.80
namedFunction · 0.70
resolveMethod · 0.65

Tested by

no test coverage detected