Skip to content

fix(filesystem): handle UNC paths on Windows in path validation#3995

Open
Will-hxw wants to merge 1 commit intomodelcontextprotocol:mainfrom
Will-hxw:fix/3756-unc-paths-windows
Open

fix(filesystem): handle UNC paths on Windows in path validation#3995
Will-hxw wants to merge 1 commit intomodelcontextprotocol:mainfrom
Will-hxw:fix/3756-unc-paths-windows

Conversation

@Will-hxw
Copy link
Copy Markdown

Summary

  • Added special handling for UNC paths (e.g. \192.168.1.1\share) in isPathWithinAllowedDirectories
  • UNC paths bypass path.resolve() which strips leading backslashes on Windows
  • After normalization, the double-backslash prefix is preserved for proper string comparison

Why

UNC paths like \192.168.1.1\share were failing validation because path.resolve() on Windows converts \server\share to \server\share (single backslash), causing the allowed directory check to fail.

Validation

  • Only path-validation.ts modified
  • Non-UNC paths unchanged (still use path.resolve)
  • UNC paths handled with special string-preservation logic

Related

Fixes Issue #3756

UNC paths (e.g. \\192.168.1.1\share\) were failing path validation
because path.resolve() strips leading backslashes on Windows.

Now UNC paths are detected and handled specially - they bypass
path.resolve() and are compared directly after normalization.

Fixes Issue modelcontextprotocol#3756
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.

1 participant