MCPcopy Create free account
hub / github.com/Noumena-Network/code / checkPathSafetyForAutoEdit

Function checkPathSafetyForAutoEdit

src/utils/permissions/filesystem.ts:630–675  ·  view source on GitHub ↗
(
  path: string,
  precomputedPathsToCheck?: readonly string[],
)

Source from the content-addressed store, hash-verified

628 * @returns Object with safe=false and message if unsafe, or { safe: true } if all checks pass
629 */
630export function checkPathSafetyForAutoEdit(
631 path: string,
632 precomputedPathsToCheck?: readonly string[],
633):
634 | { safe: true }
635 | { safe: false; message: string; classifierApprovable: boolean } {
636 // Get all paths to check (original + symlink resolved paths)
637 const pathsToCheck =
638 precomputedPathsToCheck ?? getPathsForPermissionCheck(path)
639
640 // Check for suspicious Windows path patterns on all paths
641 for (const pathToCheck of pathsToCheck) {
642 if (hasSuspiciousWindowsPathPattern(pathToCheck)) {
643 return {
644 safe: false,
645 message: `NCode requested permissions to write to ${path}, which contains a suspicious Windows path pattern that requires manual approval.`,
646 classifierApprovable: false,
647 }
648 }
649 }
650
651 // Check for NCode config files on all paths
652 for (const pathToCheck of pathsToCheck) {
653 if (isNcodeConfigFilePath(pathToCheck)) {
654 return {
655 safe: false,
656 message: `NCode requested permissions to write to ${path}, but you haven't granted it yet.`,
657 classifierApprovable: true,
658 }
659 }
660 }
661
662 // Check for dangerous files on all paths
663 for (const pathToCheck of pathsToCheck) {
664 if (isDangerousFilePathToAutoEdit(pathToCheck)) {
665 return {
666 safe: false,
667 message: `NCode requested permissions to edit ${path} which is a sensitive file.`,
668 classifierApprovable: true,
669 }
670 }
671 }
672
673 // All safety checks passed
674 return { safe: true }
675}
676
677export function allWorkingDirectories(
678 context: ToolPermissionContext,

Callers 3

isPathAllowedFunction · 0.85
isPathAllowedFunction · 0.85

Tested by

no test coverage detected