feat(filesystem): add --follow-symlinks and --symlink-depth options#3678
Open
CodeForgeNet wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
feat(filesystem): add --follow-symlinks and --symlink-depth options#3678CodeForgeNet wants to merge 3 commits intomodelcontextprotocol:mainfrom
CodeForgeNet wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
Closes modelcontextprotocol#3457 - Add followSymlinks and symlinkMaxDepth policy to lib.ts - Modify validatePath() to use lstat + hop-by-hop resolution when enabled - Circular symlink detection via visited Set - Filter -- flags from dirArgs before building allowedDirectories - 13 new test cases covering all symlink scenarios - Default behavior unchanged (followSymlinks: false)
Author
|
This implements the feature requested in #3457. Happy to make any changes based on feedback. |
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.
Closes #3457
The filesystem server currently blocks any symlink whose resolved target
falls outside the allowed directories -- no exceptions. This works well
as a default but is too rigid for common Unix workflows where symlinks
point to external storage, shared mounts, or locations managed outside
the server's root.
This PR adds two optional CLI flags:
--follow-symlinksto opt in tocross-boundary symlink resolution, and
--symlink-depth=Nto cap howmany hops outside allowed directories are permitted (default: 1).
The default behavior is unchanged. If you're not using these flags,
nothing about path validation is different.
Server Details
Motivation and Context
Users with symlinks into mounted drives, shared NFS paths, or external
directories kept having to add those paths to their allowed list manually.
The request was for an opt-in way to follow symlinks outside the boundary
without giving up all security enforcement.
The depth limit keeps it bounded: you choose how many hops outside the
allowed directories are acceptable before the server blocks access.
How Has This Been Tested?
13 new test cases in
__tests__/symlinks.test.tscovering:All existing tests (53 in
path-validation.test.ts) still pass.Breaking Changes
None. The flags are opt-in. Existing configs work exactly as before.
Types of changes
Checklist
Additional context
Circular symlinks are detected via a visited Set and throw a clear error
rather than looping. The depth counter only increments for hops that land
outside allowed directories -- hops within allowed dirs don't count against
the limit.