Skip to content

fix: denyWrite unmasks denyRead when paths overlap (#190 regression) - #195

Merged
poteat merged 2 commits into
mainfrom
atp/cc-1468-denywrite-unmasks-denyread-regression
Mar 31, 2026
Merged

poteat merged 2 commits into
mainfrom
atp/cc-1468-denywrite-unmasks-denyread-regression

Conversation

@poteat

@poteat poteat commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three fixes for Linux denyRead precedence, one of which is a #190 regression.

denyWrite unmasks denyRead (regression from #190). The reorder in #190 emits denyWrite ro-binds after the denyRead loop so .git/hooks survives a tmpfs over an ancestor. But denyWrite also emits --ro-bind <host> <host> for existing files — if the same path is in denyRead, that host-file bind now lands after --ro-bind /dev/null <host> and undoes the mask. We track masked files and skip those dests when emitting the buffered denyWrite args; the /dev/null bind already makes them read-only.

File-deny silently dropped by dir-allow. A file-level denyRead was skipped when allowRead covered its parent directory — startsWith(allowPath + '/') matched, .env stayed readable. Narrowed to exact-match only.

Iteration-order dependency. A file-deny listed before its ancestor dir-deny was wiped when the ancestor's tmpfs landed second. We normalize then sort shallow-first so ancestor mounts always land first and descendant file masks layer on top.

Thanks to @kyuz0 (#194) for reporting the first two. We took a simpler approach here that avoids the maskedDirs filtering complexity.

Links

Test Plan

  • Linux CI: three new tests in wrap-with-sandbox.test.ts — /dev/null mask present + host-file bind absent for overlapping deny lists; .env mask present despite parent in allowRead; tmpfs precedes file mask regardless of user-specified order

poteat added 2 commits March 31, 2026 10:59
…ves dir-allow

Two fixes for Linux denyRead precedence.

The #190 reorder (denyWrite after denyRead, so .git/hooks ro-binds
survive a tmpfs over an ancestor) introduced a regression: when the same
file is in both denyRead and denyWrite, denyRead's --ro-bind /dev/null
mask now lands before denyWrite's --ro-bind <host> <host>, which undoes
the mask. Track masked files and skip those dests when emitting
denyWriteArgs — the /dev/null bind already makes them read-only.

Separately: a file-level denyRead was silently skipped when allowRead
covered its parent directory (startsWith check matched). Narrow the
skip to exact matches so denyRead: ['.env'] + allowRead: ['.'] keeps
the .env deny.

Thanks to kyuz0 (#194) for reporting both.
A file-deny listed before its ancestor dir-deny in the denyRead array
was wiped: the /dev/null mask landed first, then the ancestor tmpfs
replaced it, then allowRead re-bound the project dir — file readable.

Normalize then sort by segment count before the mount loop. Ancestors
process first (tmpfs + re-binds), descendant file masks layer on top.
User-specified order no longer matters.
@poteat
poteat requested a review from dylan-conway March 31, 2026 18:27
@poteat
poteat merged commit bc1ab82 into main Mar 31, 2026
8 checks passed
@YesYouKenSpace

Copy link
Copy Markdown

Fixes #193

@poteat
poteat deleted the atp/cc-1468-denywrite-unmasks-denyread-regression branch June 12, 2026 19:27
poteat added a commit that referenced this pull request Jun 12, 2026
#190 buffers denyWrite ro-binds and emits them after the denyRead loop;
#195 masks the file-level overlap, but a directory in both deny lists
under an allowed write root gets --ro-bind <dir> <dir> stacked on top of
its own tmpfs, exposing the real contents read-only. Skip denyWrite
binds whose dest a denyRead tmpfs already hides, preserving the #190
exception for dests re-exposed by a re-bound allowed write path.

Also the inverse: a denyWrite bind over an ancestor of a denyRead dir
re-exposes it from above; re-apply the tmpfs (and its re-binds) on top.
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.

3 participants