fix(filesystem): admit paths under a UNC share root allowed directory - #5010
Merged
Merged
Conversation
path.resolve keeps the trailing separator on a UNC share root (\\server\share\), as it does on a drive root, and the prefix check in isPathWithinAllowedDirectories appended another, comparing against \\server\share\\, which nothing matches. Every path below an allowed share root was refused. Append the separator only when it is missing. The #3527 pinning test in win32.test.ts now asserts the correct behavior, with cases for a share given without a trailing separator, sibling and other shares, another server, and .. clamped at the share. Fix as proposed in #4219 by @he-yufeng (closed unmerged); root-cause analysis in #3527 by @gdimas38-eng. Co-authored-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
🦋 Changeset detectedLatest commit: fd4dff7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix preserves path boundaries and includes comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes UNC share-root containment checks in the filesystem server.
Changes:
- Avoids duplicating the separator after normalized UNC roots.
- Adds regression and boundary-security tests.
- Adds a patch changeset.
| File | Description |
|---|---|
src/filesystem/path-validation.ts |
Corrects separator-aware prefix matching. |
src/filesystem/__tests__/win32.test.ts |
Covers UNC descendants and containment boundaries. |
.changeset/filesystem-unc-share-root.md |
Documents the published fix. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
11 of 13 tasks
This was referenced Oct 5, 2026
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 #3527
Part of #5004 (Wave 2)
Description
isPathWithinAllowedDirectories()refused every path below an allowed directory that is a UNC share root.path.resolve()keeps the trailing separator on a share root (\\server\shareand\\server\share\both resolve to\\server\share\), just as it does on a drive root, and the final prefix check appended another separator, comparing against\\server\share\\, which nothing matches. Only the share root itself got through (the exact-match branch); a UNC subfolder as the allowed directory already worked, sinceresolvegives it no trailing separator.The fix appends the separator only when the resolved directory does not already end in one. The match boundary stays at a separator, so a sibling such as
\\server\share-evilis still refused.Credit: the fix is the one proposed in #4219 by @he-yufeng (closed unmerged), ported with
Co-authored-by; the root-cause analysis on #3527 is by @gdimas38-eng. Of the candidate PRs: #3615 and #3601 work from the theory thatpath.resolvecorrupts UNC paths, and both still compare against the doubled separator for a share root, so neither fixes the reported case; #4689 is about a different issue (#4686).Server Details
filesystemsrc/filesystem/path-validation.ts(the final prefix check inisPathWithinAllowedDirectories);src/filesystem/__tests__/win32.test.ts; a patch changeset.Motivation and Context
#3527: with a network share allowed (
\\server\share), listing the share works but every subdirectory and file in it is denied, so the only workaround was to list each subfolder separately.How Has This Been Tested?
There is no Windows host or real UNC share in this environment (Linux sandbox), so no Inspector or LLM-client run against a real share was possible. The change has no client surface beyond the access check, so the evidence is two targeted probes of that check with Node's
path.win32semantics:1. The pinning test, now asserting the fix.
win32.test.tsrunspath-validation.tswithpathreplaced bypath.win32andprocess.platformset towin32. TheKNOWN BUG #3527test now asserts\\server\share\subis within\\server\share\, marker removed, plus new cases. With the fix reverted (source only, new tests kept), three fail:With the fix:
Tests 15 passed (15).2. The shipped JavaScript. A Node ESM loader hook maps
pathtopath.win32and callsisPathWithinAllowedDirectoriesfrom the builtsrc/filesystem/dist/path-validation.js, and the same function transpiled fromorigin/v2/main:\\server\share\sub\\server\share\\\server\share\sub\f.txt\\server\share\\server\share\\server\share\\\server\share-evil\x\\server\share\\\server\other\x\\server\share\\server2\share\x\\server\shareC:\Temp2\a.txtC:\TempC:\Users\meC:\Security cases kept refused, as tests: a sibling share whose name extends the allowed one (
share-evil), another share on the same server, the same share on another server, and..(Node clamps..at the share root, so\\server\share\..\other\xstays inside the share, while\\server\share\sub\..\..\xis refused against\\server\share\sub).npm run local:gateexits 0 (filesystem per-file coverage at 100% lines, gate green).Breaking Changes
None. No client configuration changes. Windows users who allowed a UNC share root now get access to its contents, which is what the configuration already asked for.
Types of changes
Checklist
..cases tested)npm run changeset) if this changes what a TypeScript server publishes (.changeset/filesystem-unc-share-root.md, patch)Additional context
Kept to the one comparison in
isPathWithinAllowedDirectories, so it does not overlap the parallel path-normalization work in #5004 (#1970).🤖 Generated with Claude Code