fix(filesystem): resolve Unicode-equivalent paths - #4638
Open
KXHXK wants to merge 1 commit into
Open
Conversation
Signed-off-by: KXH <shepherdlaurie238@gmail.com>
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.
Description
Resolve filesystem paths whose requested spelling and on-disk entry differ only by Unicode normalization (for example NFC
?versus NFDe + combining acute).The normal lookup remains the fast path. After
fs.realpath()returnsENOENT, validation now walks from the most specific allowed directory and:Server Details
Motivation and Context
Fixes #4633.
This differs from #3238: normalizing strings used by the security comparison does not resolve an OS lookup when the actual directory entry uses another normalization form. This change locates the real entry and then retains the existing realpath-based security checks.
How Has This Been Tested?
npx vitest run src/filesystem/__tests__/unicode-paths.test.ts src/filesystem/__tests__/lib.test.ts --config src/filesystem/vitest.config.ts(49 passed)npm run build --workspace @modelcontextprotocol/server-filesystempath-validation.test.ts > handles root directory as allowed(D:\otherwith allowed['/']).Added real-filesystem regression coverage for:
Breaking Changes
None.
Types of changes
Checklist
Additional context
The path containment implementation itself is unchanged. The fallback only runs after
ENOENT, starts from an already allowed root, and re-checks each resolved component to prevent a normalization fallback from bypassing symlink boundaries.