fix(filesystem): preserve UNC path prefix during normalization#3920
Closed
Yanhu007 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
fix(filesystem): preserve UNC path prefix during normalization#3920Yanhu007 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Yanhu007 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
On Windows, path.normalize can strip one leading backslash from UNC paths (\\server\share → \server\share). path.resolve then interprets the single-backslash path as drive-relative (e.g. C:\server\share), causing isPathWithinAllowedDirectories to always return false for UNC network paths. Add safeNormalize() helper that detects UNC paths and restores the prefix if normalization strips it. Add tests for UNC paths. Fixes modelcontextprotocol#3756
Member
|
Thanks for working on this! We're going with #3921 which takes a slightly different approach (skipping That said, your test cases are great — we've asked the #3921 author to add UNC-specific tests based on yours. Appreciate the contribution! Closing in favor of #3921. This review was assisted by Claude Code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3756
On Windows,
path.normalizecan strip one leading backslash from UNC paths (\\server\sharebecomes\server\share).path.resolvethen interprets this as drive-relative (e.g.C:\server\share), causingisPathWithinAllowedDirectoriesto always returnfalsefor network share paths.Changes
safeNormalize()helper that detects UNC paths before normalization and restores the\\prefix if it gets strippedpath.resolve(path.normalize(...))calls withsafeNormalize()