Skip to content

fix(filesystem): fix UNC path subdirectory access denied#3633

Open
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
ctonneslan:fix/filesystem-unc-path-validation
Open

fix(filesystem): fix UNC path subdirectory access denied#3633
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
ctonneslan:fix/filesystem-unc-path-validation

Conversation

@ctonneslan
Copy link

Problem

UNC paths like \\192.168.4.96\Mega work at the root level but accessing any subdirectory (e.g. \\192.168.4.96\Mega\Drops) returns "Access denied - path outside allowed directories".

Root Cause

isPathWithinAllowedDirectories in path-validation.ts uses path.resolve(path.normalize(dir)) directly, which can mangle UNC paths by stripping or altering the leading \\ prefix. The rest of the codebase uses normalizePath() which explicitly preserves UNC prefixes (see path-utils.ts lines 66-92).

This means the allowed directory is normalized differently in the validation check than in the actual file operations, causing the startsWith() prefix check to fail.

Fix

Use normalizePath() for both the input path and allowed directory normalization in isPathWithinAllowedDirectories, ensuring consistent UNC path handling.

Fixes #3527

…pport

isPathWithinAllowedDirectories used path.resolve(path.normalize())
directly, which can mangle UNC paths (\\server\share) by stripping
the leading double backslash. The rest of the codebase uses
normalizePath() which preserves UNC prefixes.

Now uses normalizePath() for both the input path and allowed
directory normalization, ensuring consistent handling of UNC paths
in the subdirectory prefix check.

Fixes modelcontextprotocol#3527
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UNC/network share paths (\\server\share\subdir) fail access check despite being under allowed directory

1 participant