You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit de13fd2
Browse filesBrowse the repository at this point in the historyBrowse files
unknown
committed
Fix UNC path validation: cover all corruption sites on Windows
PR modelcontextprotocol#3921 fixes isPathWithinAllowedDirectories for UNC paths, but three
other sites in the filesystem server also corrupt UNC paths via
path.resolve or preserve them incorrectly through path.normalize:
1. path-validation.ts::normalizePossiblyUNCPath
path.normalize preserves trailing separators on UNC paths on Windows
(unlike path.resolve for drive paths), so 'normalizedDir + path.sep'
produces a double separator that startsWith() never matches. Strip
the trailing separator to harmonize.
2. lib.ts::validatePath
Calls path.resolve(expandedPath) before the allowed-directory check,
which on Windows corrupts UNC paths into drive-relative paths
(\\\\server\\share -> C:\\server\\share). Skip path.resolve for UNC
paths and let normalizePath handle them.
3. index.ts bootstrap
Same path.resolve corruption when normalizing allowed directories
at server startup, before they are stored via setAllowedDirectories.
Same guard applied.
All non-UNC paths retain existing behavior (path.resolve + normalize).
Tests added:
- 4 tests in path-validation.test.ts for the trailing-separator case
- 6 tests in lib.test.ts for validatePath end-to-end on UNC, gated
behind process.platform === 'win32' and using the existing fs mock
pattern
- Bug modelcontextprotocol#3 (bootstrap) has no direct unit test since UNC access in CI is
not available, but the fix applies the same principle as validatePath
and is logically covered.
Fixesmodelcontextprotocol#3756
Supersedes modelcontextprotocol#3921
0 commit comments