You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit eda9a61
Browse filesBrowse the repository at this point in the historyBrowse files
path.win32.isAbsolute() reports false for the drive-relative spelling C:name
while path.resolve() still consumes the prefix, so C:secret.txt aliased
secret.txt on Windows and C:.. slipped past the .. check, letting
splitSafeRelativePath() violate its own documented postcondition.
The rejection applies where a path is created or resolved: safe-relative
parsing, every FileStore key, Root resolve, write, create, append,
openWritable, mkdir, copyIn, and the destination of move. It does not apply to
operations on an object that already exists — reads, stat, exists, list, walk,
remove, and the source of move — because c:notes.txt is a legal POSIX filename
and refusing to read a file that exists is collateral rather than containment.
isDriveRelativePath stays internal and is absent from the published ./path
subpath.
Supersedes #85.
Co-authored-by: Yigtwxx <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@
4
4
5
5
### Security and Correctness
6
6
7
+
- Reject drive-relative segments such as `C:secret.txt` and `a/C:b` in portable relative-path parsing and every `FileStore` key, and reject leading drive-relative spellings on `Root` destinations and `resolve()` with `invalid-path`. Existing-object Root operations, including reads, inspection, removal, and the source of `move()`, continue to accept legal POSIX filenames such as `c:notes.txt`; thanks @Yigtwxx for the fix.
8
+
7
9
- Apply atomic-replacement parent-directory modes through verified no-follow descriptors on POSIX, so a directory-entry swap cannot redirect `chmod` through a symlink to an unrelated directory. Windows keeps its explicit `mkdir(mode)`-only behavior because Node does not enforce POSIX directory modes there.
8
10
- Retry a contended file-lock acquisition when Windows denies access to a lock file whose directory entry is still being torn down, including when the native binding performs the exclusive create. Both the exclusive create and the holder's snapshot read reported that transient `EPERM` as a hard failure, so concurrent `acquireFileLock()` calls failed intermittently on Windows even though the very next attempt would have succeeded. Retries stay bounded, so a genuine permission denial still surfaces as `EPERM` rather than a lock timeout; thanks @Yigtwxx for the fix.
9
11
- Apply `replaceFileAtomic()` and `replaceFileAtomicSync()` modes through pinned temp-file descriptors before rename, and through pinned copy-fallback descriptors, so a post-rename symlink swap cannot redirect `chmod` to an unrelated file while exact modes remain independent of umask; thanks @yetval for reporting this (#86).
Copy file name to clipboardExpand all lines: docs/errors.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,7 +96,7 @@ type FsSafeErrorCode =
96
96
|`helper-failed`| A native mechanism or multi-step operational helper failed. | Inspect `cause` and any operation-specific `details`; retrying may be unsafe if the operation partially completed. |
97
97
|`helper-unavailable`| Required native binding could not be loaded. | Unsupported platform, missing/incompatible bundled binary, or `FS_SAFE_NATIVE_MODE=require`. `auto` falls back where possible; `require` fails closed. |
98
98
|`insecure-permissions`| A secure file or path permission check found a mode/ACL that allows broader access than requested. | File or directory is group/world writable/readable; Windows ACL grants broad read. |
99
-
|`invalid-path`| Input was empty, contained NUL, was an unparseable URL, or otherwise unusable. | Caller didn't validate input; input was a network path on Windows. |
99
+
|`invalid-path`| Input was empty, contained NUL, was an unparseable URL, or otherwise unusable. | Caller didn't validate input; input was a network path on Windows, a drive-relative segment in a portable relative path or store key, or a leading drive-relative spelling such as `C:name` used as a Root destination. Existing-object Root lookups retain legal POSIX drive-like names. |
100
100
|`not-empty`|`remove()` on a non-empty directory. | Use `replaceDirectoryAtomic` or remove children first. |
101
101
|`not-file`| Read or copy targeted a non-regular file. | Target was a directory, FIFO, socket, device. |
102
102
|`not-found`| The target does not exist (or its parent does not, with `mkdir: false`). | Typical missing-file case. |
Copy file name to clipboardExpand all lines: docs/file-store.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,13 @@ type FileStore = {
64
64
65
65
`path()` returns the absolute path the store would use, after asserting it stays inside `rootDir`. Useful for logging or for handing to other libraries.
66
66
67
+
Every `relativePath` is a portable store key, including keys passed to reads,
68
+
`exists`, and `remove`. A segment with a Windows drive-relative spelling such
69
+
as `C:name` (including an embedded segment such as `a/C:name`) throws
70
+
`invalid-path` on every platform. This prevents a key created on POSIX from
71
+
aliasing a different file when the store is moved to Windows. Colons elsewhere,
72
+
such as the timestamp in `logs/2026-08-02T10:30:00Z.log`, remain valid.
73
+
67
74
`root()` returns a [`Root`](root.md) handle for the same directory when you need the full surface (move, list, mkdir). It's a fresh handle per call and is safe to call frequently.
Copy file name to clipboardExpand all lines: docs/root.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,14 @@ fs.ensureRoot(options?) // accepts "" / "." as the root itself
103
103
104
104
`copyIn` is a one-shot ingest from a trusted absolute source path: it streams the source through the boundary, atomically renames into the root, and respects `maxBytes`.
105
105
106
+
Root operations that choose a new destination reject a leading Windows
107
+
drive-relative spelling such as `C:name` on every platform. This applies to
108
+
`write`, `create`, `append`, `openWritable`, `mkdir`, `copyIn`, and the
109
+
destination argument of `move`. In particular, `copyIn(path.basename(source),
110
+
source)` can reject a legal POSIX basename such as `c:photo.png`; callers that
111
+
derive portable destination names from host files must sanitize or map that
112
+
basename first.
113
+
106
114
`openWritable` opens a writable file with options `mode?:number` and `writeMode?:"replace"|"append"|"update"`. `replace` truncates existing files and is the default; `update` keeps existing contents. Use it for streaming output. Prefer `awaitusing` for cleanup.
107
115
108
116
All mutation methods accept `denyMutations?: { paths?: string[]; prefixes?:string[] }`. Entries must be absolute paths. `paths` blocks those exact paths; `prefixes` blocks those paths and their descendants. fs-safe preserves path strings exactly and canonicalizes through existing ancestors before comparing, so a symlinked ancestor to a denied location is still denied. Denied mutations throw `FsSafeError` with code `denied-path`. Use this for caller-specific sensitive paths, not as a replacement for the root boundary, symlink, or hardlink checks.
@@ -119,6 +127,12 @@ fs.resolve(rel) // absolute path inside the root, after canonic
119
127
120
128
These do not pin a later operation. They are safe to expose to UIs and decision points; for the actual read or write, use the verb methods so the operation pins identity at the point of use.
121
129
130
+
`resolve()` is the exception to the existing-object rule: because it selects a
131
+
location for later use, it rejects a leading drive-relative spelling. Reads,
132
+
`stat`, `exists`, `list`, `walk`, `remove`, and the source argument of `move`
133
+
accept an existing POSIX filename such as `c:notes.txt`. For `move`, only the
134
+
new destination name is subject to the portable guard.
135
+
122
136
## Native helper mode
123
137
124
138
Create-only writes prefer the bundled native helper for fd-relative opens and
@@ -151,7 +165,7 @@ Every method throws `FsSafeError` with a `code`. Branch on `err.code`, not messa
151
165
152
166
| Code | When it fires |
153
167
|---|---|
154
-
| `invalid-path` | The input path is malformed, including embedded NUL bytes. |
168
+
| `invalid-path` | The input path is malformed, including embedded NUL bytes. Portable relative-path helpers and `FileStore` keys reject drive-relative segments; Root destination and resolution operations reject a leading drive-relative spelling such as `C:name`. |
155
169
| `outside-workspace` | The input resolves outside the root, or contains a `..` segment that would escape it. |
156
170
| `not-found` | The target does not exist (or its parent does not, with `mkdir: false`). |
157
171
| `not-file` | A read or copy targeted a non-regular file (directory, FIFO, socket, …). |
0 commit comments