Repository navigation
fix(windows): gate shares before case-folded containment checks - #784
Conversation
Review found that the library's other lexical containment checks fold Unicode case (Windows path.relative, the Root prefix identity match, isPathInside), so a host spelled with U+212A KELVIN SIGN compared as the trusted ASCII host and was then probed before the ASCII-only share gate ran. Run the share/device gate first in prepareRootTraversal (before the case-fold identity lookup), in the pathScope lexical core, in isPathInside, and in the secret-file containment check. A spelling exactly under a trusted boundary, without climbing above it, is never foreign, which keeps Roots on GLOBALROOT shadow-copy paths working. Refine namespace spellings: their authority (head, plus host and share for UNC) must not be empty or end in a dot or space, and later all-dot or all-space components may not climb above it; otherwise the target is unidentifiable. Local namespaced-drive spellings such as \\?\C:\a\..\b stay local. Document the intentional cross-share compatibility change and the upgrade path: pass boundary-relative paths or spell them on the boundary's own share.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 10:42 PM ET / October 1, 2026, 02:42 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch checks Windows share and device boundaries before case-folded path containment, preserves explicitly trusted namespace children, and updates regression tests and compatibility documentation. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main still permits the early Unicode-folded admission paths identified in the report. No introduced correctness or security defect was found, and the previous review’s cleared findings remain resolved. Priority: P0 Review scores
Verification
How this fits togetherfs-safe checks caller-supplied paths against trusted filesystem roots before Node performs reads, writes, or metadata lookups. Windows share admission prevents rejected paths from first contacting an attacker-selected network host. flowchart LR
A[Caller supplied path] --> B[Share and device admission]
C[Trusted filesystem root] --> B
B --> D[Containment and identity checks]
B --> E[Reject foreign authority]
D --> F[Guarded filesystem operation]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep Windows authority admission ahead of identity and fallback lookups, with trusted-share support and explicit cross-share upgrade guidance. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the path: current main performs Unicode-folded Root admission before authority rejection, and the supplied Windows A/B trace demonstrates related containment failures. No target code was executed during this read-only review. Is this the best way to solve the issue? Yes, moving authority checks into the shared admission points addresses the demonstrated probes without duplicating filesystem operations or changing stored state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b0429464a423. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
…efold-gates # Conflicts: # CHANGELOG.md
Problem
Follow-up to #781, which landed the Windows share/device gate (reject UNC and device-namespace paths before any filesystem call). ClawSweeper's review of #781 found three paths where a caller-supplied network spelling could still be probed before that gate decided:
prepareRootTraversalran the gate only after direct root-prefix admission, whose Windows case-fold branch inspects the caller's prefix identity (lstat).pathScope.existing/files: a lexically accepted path that is missing under the Root falls back toresolveNearestExistingPathon the caller's spelling.path.relativecontainment check passes, then queue-key canonicalizationlstats the caller's path.Root cause
The share key in #781 deliberately folds ASCII case only, because Unicode folding is not how Windows resolves host names (U+212A KELVIN SIGN lowercases to
k, while an attacker can answer LLMNR/NetBIOS lookups for the distinct name). But the library's other lexical containment checks fold Unicode case: Windowspath.relative, the Root prefix identity match, andisPathInside. So\\fs-safe-Kost\share\root\xwritten with a Kelvin sign compared as inside\\fs-safe-kost\share\root, and the code then touched the caller's spelling before the ASCII gate ran.Fix
The share/device decision now runs first at the shared lexical choke points rather than at individual call sites:
prepareRootTraversal: before direct admission (so the case-fold identity lookup never sees a foreign spelling)pathScope's lexical corepathStaysWithinRoot(coversresolve,resolveAll,existing,files,writable,ensureDir)isPathInside(covers root-context, install-path, symlink-parents,isPathInsideWithRealpathand other users)assertPathWithinRoot(both the queue key and write preparation)A path spelled exactly under a trusted boundary (byte prefix, no
..climbing above it) is never foreign, so Roots on\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopyN\...keep working now that the gate runs first.The namespace rule is also more precise. For
\\?\and\\.\spellings, the authority (head; plus host and share for UNC) must not be empty or end in a dot or space, which Win32 would rewrite. Later all-dot/space components may not climb above it (\\.\C:\..\UNC\hostresolves to UNC in both Node and Win32), and GLOBALROOT/Global stay unidentifiable. Local spellings such as\\?\C:\root\a\..\band\\?\C:\x.stay local instead of being rejected.Owner decision: cross-share aliases
The maintainer's brief for #781 requires absolute inputs that are not lexically inside the boundary, in particular UNC and device-namespace paths, to be rejected lexically before any filesystem access. Accordingly, an absolute path on a different share or device is rejected even if a filesystem alias would resolve it back inside the boundary. Docs (
security-model.md,path.md) and the changelog now state this and the upgrade path: pass boundary-relative paths, or spell them on the boundary's own share. The boundary's own share (ASCII case-insensitive), local alias walks, and namespaced drives are unchanged.Proof
New regressions in
test/windows-share-root-admission.test.ts:isPathInsiderejects the Kelvin host while ASCII-case variants and exact GLOBALROOT children stay inside. Root direct admission with a Kelvin-host candidate is rejected with nonode:fscall receiving the Kelvin spelling.pathScopelexical methods and both secret writers reject the Kelvin host with no fs call. Also a real network Root on the runner's\\localhost\<drive>$admin share: the same-share\\LOCALHOST\...spelling resolves to the in-root file, while\\127.0.0.1\...(another share key, same machine) is rejected with no fs call receiving that spelling. This case skips itself only when the admin share is unreachable.Negative control: moving the Root gate back after direct admission and removing the
isPathInsidegate makes both POSIX regressions fail, and the Root case recordslstaton the Kelvin-host prefix.Local (macOS): full
pnpm test13,229 passed (only the known locally unbuildable allocator artifact suite fails); typecheck,lint:file-size,lint:fs-boundary,docs:check,git diff --checkpass.Autoreview (Codex, P1): the four remaining findings were INDEX-only, describing the pre-fix committed state that this commit replaces; no working-tree findings.
Real Windows A/B on
fs-safe-windows-16core: run 36803970186 (throwaway diag branch: this change plus a setup file recording everynode:fscall whose argument starts with two separators; JavaScript fallback; Node 22 and 24;beforerestoressrc/from main 900a770, tests unchanged; verbose reporter).isPathInsiderejects a Kelvin-sign host under an ASCII sharepathScopelexical methods and both secret writers reject a Kelvin-sign host, no fs call\\localhost\C$\…: same-share\\LOCALHOST\c$\…resolves to the in-root file;\\127.0.0.1\C$\…(other share key, same machine) rejected with no fs callIn the after legs, every recorded UNC-shaped fs call (22 per Node version) targets the trusted
\\localhost\C$Root or its same-share\\LOCALHOST\c$spelling; none target the Kelvin host,127.0.0.1, or a canary host. The Root direct-admission Kelvin regression is POSIX-runnable (platform spoof) and is covered by the local negative control above, where the old ordering recordslstaton the Kelvin-host prefix.