Skip to content

fix(boundary): resolve root prefix and permission checks on Windows (#2774) - #2802

Open
isihussain wants to merge 1 commit into
danielmiessler:mainfrom
isihussain:fix/boundary-cross-platform-path-containment
Open

isihussain wants to merge 1 commit into
danielmiessler:mainfrom
isihussain:fix/boundary-cross-platform-path-containment

Conversation

@isihussain

Copy link
Copy Markdown

Summary

Fixes #2774.

The Boundary.ts module provides system-wide path containment and atomic write primitives (confinedPath, �tomicWrite). On Windows systems, two defects caused all boundary-checked absolute writes and memory operations to fail:

  1. Path Containment (confinedPath): Absolute walks initialized cur to sep (). On Windows, \C: was queried via lstatSync, producing ENOENT on drive-letter paths and causing every valid absolute path inside the root boundary to be refused as
    ull. Additionally, paths using mixed / and \ separators were not split properly.
  2. Permission Invariants (�tomicWrite): (fstatSync(fd).mode & 0o777) === mode checked POSIX permission bits. On Windows, file modes report o666, causing atomic file writes to throw an InvariantViolation.

Solution

  1. In confinedPath(), initialize cur from parse(p).root for absolute paths and split components with /[\/]+/ to handle both separators uniformly.
  2. In ensureDir() and �tomicWrite(), gate POSIX-specific permission mode invariants and chmodSync() to process.platform !== "win32".
  3. Added Boundary.test.ts covering path containment, directory traversal rejection (..), and atomic write verification.

Signed-off-by: isihussain isihussain@users.noreply.github.com

…anielmiessler#2774)

In confinedPath(), absolute path resolution previously initialized cur to sep
('/', or '\' on Windows). On Windows, this prepended a backslash to drive letters
('\C:'), producing ENOENT and causing every absolute path inside root to be
wrongly refused as null. Additionally, paths with mixed forward/backward slashes
were not split consistently.

In atomicWrite(), the mode invariant checked POSIX permission bits (0o777),
which always fails on Windows where fstat reports 0o666.

Fix confinedPath to initialize rootPrefix from parse(p).root and split path
segments on both '/' and '\'. Gate POSIX permission checks and chmodSync in
ensureDir and atomicWrite to non-Windows platforms. Add Boundary.test.ts
covering path containment, traversal rejection, and atomic file creation.

Closes danielmiessler#2774

Signed-off-by: isihussain <isihussain@users.noreply.github.com>
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.

[bug] Windows: memory writes and statusline fail on a fresh install (POSIX-only path…

1 participant