Skip to content

fix(filesystem): normalize UNC paths in access check#3601

Open
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:fix/issue-3527-unc-path-access-check
Open

fix(filesystem): normalize UNC paths in access check#3601
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:fix/issue-3527-unc-path-access-check

Conversation

@nielskaspers
Copy link
Contributor

Summary

UNC/network share paths (\\server\share\subdir) fail the access check in isPathWithinAllowedDirectories() despite the parent share being in the allowed directories list. The root listing works but any subdirectory access fails.

Root cause: path-validation.ts used path.resolve(path.normalize(...)) to normalize paths, which can mangle the \\ prefix on UNC paths on Windows. Meanwhile, path-utils.ts already has a normalizePath() function with explicit UNC path handling that preserves the prefix correctly.

Fix: Use normalizePath() from path-utils.ts in isPathWithinAllowedDirectories() instead of raw path.resolve(path.normalize(...)), ensuring both the requested path and allowed directories are normalized consistently for UNC paths.

All 145 existing tests pass.

Fixes #3527

Use normalizePath() from path-utils instead of raw path.resolve(path.normalize())
in isPathWithinAllowedDirectories(). The normalizePath function has explicit UNC
path handling that preserves the \\ prefix, whereas path.resolve can mangle UNC
paths on Windows, causing subdirectory access checks to fail even when the parent
UNC share is in the allowed directories list.

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