fix: preserve UNC path prefix in isPathWithinAllowedDirectories - #3791
fix: preserve UNC path prefix in isPathWithinAllowedDirectories#3791hashwnath wants to merge 1 commit into
Conversation
|
@claude review |
|
Claude finished @cliffhall's task in 1m 35s —— View job PR Review: fix: preserve UNC path prefix in isPathWithinAllowedDirectoriesTasks:
SummaryThis is a well-targeted, minimal fix for a real Windows bug. The approach is sound and the existing test suite provides good coverage for non-UNC paths. A few concerns worth addressing below. What the PR DoesTwo private helpers are added to function isUNCPath(p: string): boolean {
return p.startsWith('\\\\') && !p.startsWith('\\\\?\\');
}
function normalizePath(p: string): string {
if (isUNCPath(p)) {
const normalized = path.normalize(p);
if (!normalized.startsWith('\\\\')) {
return '\\' + normalized; // restore stripped leading \
}
return normalized;
}
return path.resolve(path.normalize(p));
}And the two inline Issues1. No dedicated unit tests for The only UNC test is at line 432 of
2. The prefix-restoration branch is untested The recovery branch: if (!normalized.startsWith('\\\\')) {
return '\\' + normalized;
}has no test that exercises it. If 3. Correctness of the restoration logic The logic looks correct for the documented bug (Node.js stripping one 4. Paths like 5. Case sensitivity for UNC paths This is a pre-existing issue, not introduced by this PR: UNC hostnames on Windows are case-insensitive ( Positives
MinorThe whitespace change on line 7 of the diff ( VerdictApprove with suggestions. The core fix is correct and the security model is unchanged. The main gap is test coverage — the new helpers should have at least a few platform-unconditional tests so CI catches any future regression. The restoration branch ( |
LuuOW
left a comment
There was a problem hiding this comment.
Technical audit: Verified MCP server implementation for consistency with current SDK patterns.
Summary
Fixes #3756
On Windows,
isPathWithinAllowedDirectoriesfails for UNC paths (e.g.\\server\share\project) becausepath.resolve(path.normalize(...))can corrupt the UNC prefix — stripping a leading backslash and turning\\server\shareinto\server\share, whichpath.resolvethen interprets as drive-relative (e.g.C:\server\share). This causes all UNC path access to fail with "Access denied - path outside allowed directories".Fix
Extract path normalization into a
normalizePath()helper that detects UNC paths and normalizes them withoutpath.resolve:\\server\share\...) are always absolute, sopath.normalizealone is sufficient\\prefix is preserved; restore it if strippedpath.resolve(path.normalize(...))as beforeTest plan
\\192.168.x.x\share), files within the share are now accessible