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

Function sensitiveDirectoryRefusal

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

Source from the content-addressed store, hash-verified

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