Repository navigation
fix(sandbox): refcount temporary roots so one holder's cleanup cannot revoke another's #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kevincodex1
merged 11 commits into
Twigpine:main
from
gnanam1990:split/6-sandbox-temp-refcount
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6c6248e
fix(sandbox): a temporary root is refcounted, so one holder's cleanup…
gnanam1990 69f7dc8
fix(sandbox): a read covered by a TEMPORARY write root takes a refere…
gnanam1990 0367d4e
test(sandbox): make the concurrency test concurrent, and portable off…
gnanam1990 5752bec
fix(sandbox): a permanent grant outlives the temporary one, and an un…
gnanam1990 36b7a50
chore(sandbox): re-request an automated review of this head
gnanam1990 42705b5
test(sandbox): a fixture failure fails, a report cannot deadlock, and…
gnanam1990 4b60a35
fix(sandbox): a reader outliving its writer keeps read authority, not…
gnanam1990 4e66233
fix(sandbox): a nested write holder keeps only the subtree it asked for
gnanam1990 53233c7
test(sandbox): the outside-roots fixture fails loudly instead of skip…
gnanam1990 96f4299
fix(sandbox): least authority for nested readers, and a hermetic gran…
gnanam1990 0697a9d
refactor(sandbox): drop the child-grant accessors this PR does not co…
gnanam1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package sandbox | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| // THE ANTI-ESCALATION PROPERTY. A read grant (AddRead, where --add-read-dir lands) | ||
| // is READABLE but NOT WRITABLE. This is what makes propagating a parent's | ||
| // request_permissions read grant to a child safe: the child can audit the granted | ||
| // path but cannot modify it. Emitting the grant as a WRITE root (--add-dir) would | ||
| // break exactly this. | ||
| func TestAReadGrantIsReadableButNotWritable(t *testing.T) { | ||
| scope, granted := grantOutsideDefaults(t) | ||
| root, err := scope.AddRead(granted) | ||
| if err != nil { | ||
| t.Fatalf("AddRead: %v", err) | ||
| } | ||
| target := filepath.Join(root, "audit-me.go") | ||
|
|
||
| if block := scope.validateRead(target); block != nil { | ||
| t.Fatalf("a read grant did not allow READING %q: %v — the audit would fail 'outside the workspace'", target, block) | ||
| } | ||
| if block := scope.validate(target); block == nil { | ||
| t.Fatalf("a read grant ALLOWED WRITING %q — a read grant escalated to write", target) | ||
| } | ||
| } | ||
|
|
||
| // grantOutsideDefaults returns a scope and a directory that scope does not | ||
| // already cover, both under test-owned storage. | ||
| // | ||
| // THE CAUSE, NOT THE SYMPTOM. NewScope seeds the system temporary directory as a | ||
| // permanent write root, so a plain t.TempDir() grant is writable before any | ||
| // grant exists and the anti-escalation assertions below prove nothing. The first | ||
| // fix placed the fixture under os.UserHomeDir() to find ground the defaults do | ||
| // not own. That worked and bought two problems: a hermetic runner may expose | ||
| // HOME read-only, so these tests failed at MkdirTemp before asserting anything, | ||
| // and on an ordinary machine they wrote into the developer's real home and left | ||
| // zero-scope-* debris whenever a run was interrupted. Reported by @jatmn. | ||
| // | ||
| // Building the Scope directly removes the seeded defaults, which is what made | ||
| // HOME necessary in the first place. t.TempDir() is then outside by | ||
| // construction, the fixture is hermetic, and nothing touches HOME. | ||
| func grantOutsideDefaults(t *testing.T) (*Scope, string) { | ||
| t.Helper() | ||
| workspace := resolvedFixturePath(t, t.TempDir()) | ||
| granted := resolvedFixturePath(t, t.TempDir()) | ||
| scope := &Scope{workspaceRoot: workspace} | ||
| // PROVED AGAINST THIS SCOPE. The point of the helper is that the grant is | ||
| // what changes access, so the target has to begin unauthorised — asserted | ||
| // here once rather than trusted in every caller. | ||
| if scope.validate(filepath.Join(granted, "probe.txt")) == nil { | ||
| t.Fatalf("%s is writable before any grant exists; the assertions below would prove nothing", granted) | ||
| } | ||
| return scope, granted | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.