fix(windows): skip TooWide folders in WinDrive.Above to preserve list_profile #179

Merged
HumanBean merged 1 commit from cfw34683/Beanstalk:fix/windows-above-skip-toowide into main 2026-12-05 17:04:07 +00:00
Contributor

Summary

Prevents WindowsSandbox from granting WinAccess.List (FILE_LIST_DIRECTORY) on USERPROFILE / LOCALAPPDATA / Users when home.Data is in the default %LOCALAPPDATA%\Beanstalk\data location.

Cause

WindowsSandbox.cs iterates WinDrive.Above(home.Data) and applies WinAccess.List (0x00100081, which includes FILE_LIST_DIRECTORY), granting the AppContainer SID and beanstalk-runner (S,RD,RA) on %USERPROFILE%. WindowsSelfTest.cs (list_profile) then immediately fails because the sandbox can list %USERPROFILE%.

Fix

  • Added WinDrive.SafeAbove(path, tooWide) in agent/Core/WindowsPlan.cs to filter out WinHost.TooWide() paths.
  • Switched WindowsSandbox.cs to WinDrive.SafeAbove(home.Data, WinHost.TooWide()).
  • Added unit test coverage in agent/tests/agent_core/WindowsChecks.cs.

Verification

  • dotnet build agent\tests\agent_core\AgentCoreTests.csproj --configuration Release succeeded (0 Warning(s), 0 Error(s)).
### Summary Prevents `WindowsSandbox` from granting `WinAccess.List` (`FILE_LIST_DIRECTORY`) on `USERPROFILE` / `LOCALAPPDATA` / `Users` when `home.Data` is in the default `%LOCALAPPDATA%\Beanstalk\data` location. ### Cause `WindowsSandbox.cs` iterates `WinDrive.Above(home.Data)` and applies `WinAccess.List` (`0x00100081`, which includes `FILE_LIST_DIRECTORY`), granting the AppContainer SID and `beanstalk-runner` `(S,RD,RA)` on `%USERPROFILE%`. `WindowsSelfTest.cs` (`list_profile`) then immediately fails because the sandbox can list `%USERPROFILE%`. ### Fix - Added `WinDrive.SafeAbove(path, tooWide)` in `agent/Core/WindowsPlan.cs` to filter out `WinHost.TooWide()` paths. - Switched `WindowsSandbox.cs` to `WinDrive.SafeAbove(home.Data, WinHost.TooWide())`. - Added unit test coverage in `agent/tests/agent_core/WindowsChecks.cs`. ### Verification - `dotnet build agent\tests\agent_core\AgentCoreTests.csproj --configuration Release` succeeded (`0 Warning(s), 0 Error(s)`).
fix(windows): skip TooWide folders in WinDrive.Above to preserve list_profile
Some checks failed
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Coordinator tests (pull_request) Has been cancelled
CI / Agent build and checks (pull_request) Has been cancelled
CI / Coordinator image (pull_request) Has been cancelled
f0cae3a4eb
Member

Possibly related, for context:

  • PR #165 fix(agent): the Windows sandbox lists the folders above its data folder, so lld's start from the real path is not refused — Prior merged change introduced the broad parent-folder listing grants this narrows.
Possibly related, for context: - PR #165 fix(agent): the Windows sandbox lists the folders above its data folder, so lld's start from the real path is not refused — Prior merged change introduced the broad parent-folder listing grants this narrows.
Owner

Has this been ran fully?

@review

Has this been ran fully? @review
BeanBot left a comment

Recommendation: Request changes. The change leaves previously granted profile permissions in place, so affected Windows installations can continue to fail the sandbox self-test. The Windows behavior has not been verified in a run.

The filter prevents new listing grants on paths classified as too wide, protecting profile listings on fresh setups. Existing ACLs persist, however, and removing ancestor listings could affect Windows tool startup.

Blocking (2): must change before merging.

  1. L1 agent/Core/WindowsSandbox.cs:120: Skipping broad folders does not remove listing ACEs already granted by earlier versions. (more on the line) Do: Revoke the old broad-folder grants for the affected sandbox SIDs during migration, handling failures safely, and test an upgrade from an existing grant.
  2. L4: It conflicts with its base branch: bring it up to date (@​fix or @​rebase try first). (for the author)

Nits (1): optional.

  • L2 docs/windows-clang.md:47: The Windows clang documentation still says preparation grants listings on the profile and Local folders. When: A maintainer diagnosing LLVM permissions is told those grants exist even though this change skips them on a fresh setup. Do: Update the ancestor-grant description to match the filter and any migration behavior.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3 agent/Core/WindowsSandbox.cs:120: The changed Windows permissions have not been exercised in a sandbox or a build. (more on the line) Do: Run the Windows sandbox self-test and a real compile and link on a fresh default-path setup, then repeat the self-test after upgrading a setup with the old grants. Exercise both sandbox modes where available.

@fix can do L1 and L2.

Questions (1) (not confirmed from the code; they don't hold the recommendation)

  • agent/tests/agent_core/WindowsChecks.cs:130: Is there a current case where sandbox preparation grants listing on the profile despite this test passing?

Checks: Still running: 5 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The PR reports a successful test-project build, but no executed self-test or Windows build demonstrating the fix.

Other systems: The changed path is Windows-only and applies to both AppContainer and the runner-account fallback when a work drive is available. LLVM tools can resolve paths back through the omitted ancestors; the repository records a prior linker startup failure on that path. Linux sandbox behavior is unchanged.

Switches: None added, changed, or removed.

Reviewed: f0cae3a4eb against b3e6a7d97a: Read the repository rules, commit and complete diff, the changed sandbox path, ACL handling, self-test, work-drive logic and the added test. Skimmed portions of the larger changed files and the surrounding documentation; no review checklist or pull request template was present.; nothing run (a code review).

Checked and fine:

  • The filter normalizes paths and compares them without case.
  • The diff adds no game-derived files, dependencies, or switches.
  • The reported build is described as a build, not as an executed test.

Testing: No code or tests were run during review. The PR reports a successful Release build of AgentCoreTests; CI checks were still running.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The change leaves previously granted profile permissions in place, so affected Windows installations can continue to fail the sandbox self-test. The Windows behavior has not been verified in a run. The filter prevents new listing grants on paths classified as too wide, protecting profile listings on fresh setups. Existing ACLs persist, however, and removing ancestor listings could affect Windows tool startup. **Blocking (2)**: must change before merging. 1. **L1** `agent/Core/WindowsSandbox.cs:120`: Skipping broad folders does not remove listing ACEs already granted by earlier versions. (more on the line) **Do:** Revoke the old broad-folder grants for the affected sandbox SIDs during migration, handling failures safely, and test an upgrade from an existing grant. 2. **L4**: It conflicts with its base branch: bring it up to date (`@​fix` or `@​rebase` try first). *(for the author)* **Nits (1)**: optional. - **L2** `docs/windows-clang.md:47`: The Windows clang documentation still says preparation grants listings on the profile and Local folders. *When:* A maintainer diagnosing LLVM permissions is told those grants exist even though this change skips them on a fresh setup. **Do:** Update the ancestor-grant description to match the filter and any migration behavior. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3** `agent/Core/WindowsSandbox.cs:120`: The changed Windows permissions have not been exercised in a sandbox or a build. (more on the line) **Do:** Run the Windows sandbox self-test and a real compile and link on a fresh default-path setup, then repeat the self-test after upgrading a setup with the old grants. Exercise both sandbox modes where available. `@fix` can do L1 and L2. **Questions (1)** (not confirmed from the code; they don't hold the recommendation) - `agent/tests/agent_core/WindowsChecks.cs:130`: Is there a current case where sandbox preparation grants listing on the profile despite this test passing? **Checks:** Still running: 5 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The PR reports a successful test-project build, but no executed self-test or Windows build demonstrating the fix. **Other systems:** The changed path is Windows-only and applies to both AppContainer and the runner-account fallback when a work drive is available. LLVM tools can resolve paths back through the omitted ancestors; the repository records a prior linker startup failure on that path. Linux sandbox behavior is unchanged. **Switches:** None added, changed, or removed. **Reviewed:** f0cae3a4ebdd against b3e6a7d97a17: Read the repository rules, commit and complete diff, the changed sandbox path, ACL handling, self-test, work-drive logic and the added test. Skimmed portions of the larger changed files and the surrounding documentation; no review checklist or pull request template was present.; nothing run (a code review). **Checked and fine:** - The filter normalizes paths and compares them without case. - The diff adds no game-derived files, dependencies, or switches. - The reported build is described as a build, not as an executed test. **Testing:** No code or tests were run during review. The PR reports a successful Release build of AgentCoreTests; CI checks were still running. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -118,3 +118,3 @@
WinAcl.Apply(grants, Sid, Ledger, LowLabel, skipped);
if (drive != null)
foreach (var above in WinDrive.Above(home.Data))
foreach (var above in WinDrive.SafeAbove(home.Data, WinHost.TooWide()))
Member

L1 (blocking): Skipping broad folders does not remove listing ACEs already granted by earlier versions.

When: After the previous code grants the sandbox SID listing access to the profile, updating to this version leaves that ACE in place. The self-test can still list the profile and rejects the sandbox, so the affected agent remains unable to take jobs.

Do: Revoke the old broad-folder grants for the affected sandbox SIDs during migration, handling failures safely, and test an upgrade from an existing grant.

**L1** (blocking): Skipping broad folders does not remove listing ACEs already granted by earlier versions. *When:* After the previous code grants the sandbox SID listing access to the profile, updating to this version leaves that ACE in place. The self-test can still list the profile and rejects the sandbox, so the affected agent remains unable to take jobs. **Do:** Revoke the old broad-folder grants for the affected sandbox SIDs during migration, handling failures safely, and test an upgrade from an existing grant.
Member

L3 (should fix): The changed Windows permissions have not been exercised in a sandbox or a build.

When: With the default data path, profile and Local listings are withheld; the self-test must pass without them, and LLVM tools that resolve a real path must still start and link.

Do: Run the Windows sandbox self-test and a real compile and link on a fresh default-path setup, then repeat the self-test after upgrading a setup with the old grants. Exercise both sandbox modes where available.

**L3** (should fix): The changed Windows permissions have not been exercised in a sandbox or a build. *When:* With the default data path, profile and Local listings are withheld; the self-test must pass without them, and LLVM tools that resolve a real path must still start and link. **Do:** Run the Windows sandbox self-test and a real compile and link on a fresh default-path setup, then repeat the self-test after upgrading a setup with the old grants. Exercise both sandbox modes where available.
cfw34683 force-pushed fix/windows-above-skip-toowide from f0cae3a4eb
Some checks failed
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Coordinator tests (pull_request) Has been cancelled
CI / Agent build and checks (pull_request) Has been cancelled
CI / Coordinator image (pull_request) Has been cancelled
to 92230c2d8d
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Coordinator tests (pull_request) Blocked by required conditions
CI / Agent build and checks (pull_request) Blocked by required conditions
CI / Coordinator image (pull_request) Blocked by required conditions
2026-12-05 13:38:45 +00:00
Compare
Author
Contributor

Rebased onto main (adde94b, which already includes WinDrive.SafeAbove from #180) and addressed BeanBot's review items in 92230c2:

  • L4 (blocking): Rebased cleanly onto main — no conflicts.
  • L1 (blocking): Added WinDrive.WideAbove(path, tooWide), a HasExplicitAce() short-circuit in WinAcl.Set for REVOKE_ACCESS (so already-clean/unowned folders are a fast no-op), and migration revocation in WindowsSandbox.Prepare to strip stale sandbox SID ACEs from TooWide ancestors (catching WinError safely on unowned folders like C:\Users). Added unit tests for SafeAbove, WideAbove, and a Windows NTFS upgrade-revocation test in WindowsChecks.cs.
  • L2 (nit): Updated docs/windows-clang.md to document SafeAbove and stale broad-folder grant revocation.

Verified dotnet build agent/App and dotnet build agent/tests/agent_core -c Release pass with 0 warnings, 0 errors.

Rebased onto `main` (`adde94b`, which already includes `WinDrive.SafeAbove` from #180) and addressed BeanBot's review items in `92230c2`: - **L4 (blocking):** Rebased cleanly onto `main` — no conflicts. - **L1 (blocking):** Added `WinDrive.WideAbove(path, tooWide)`, a `HasExplicitAce()` short-circuit in `WinAcl.Set` for `REVOKE_ACCESS` (so already-clean/unowned folders are a fast no-op), and migration revocation in `WindowsSandbox.Prepare` to strip stale sandbox SID ACEs from `TooWide` ancestors (catching `WinError` safely on unowned folders like `C:\Users`). Added unit tests for `SafeAbove`, `WideAbove`, and a Windows NTFS upgrade-revocation test in `WindowsChecks.cs`. - **L2 (nit):** Updated `docs/windows-clang.md` to document `SafeAbove` and stale broad-folder grant revocation. Verified `dotnet build agent/App` and `dotnet build agent/tests/agent_core -c Release` pass with 0 warnings, 0 errors.
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The migration removes stale explicit grants for the sandbox SID when it can update the affected ACLs, but its effect on sandbox checks and a real Windows build has not been demonstrated. Recommend approval; not approved on the forge.

The change revokes old broad-ancestor permissions during Windows sandbox preparation and adds an idempotent ACL check. It preserves the existing safe-ancestor grants, at the cost of inspecting the affected ACLs during preparation.

Nits (1): optional.

  • L2 docs/windows-clang.md:47: The safe-ancestor examples still include Local, although LOCALAPPDATA is excluded by WinHost.TooWide. When: A maintainer diagnosing LLVM permissions is told those grants exist even though this change skips them on a fresh setup. Do: Remove Local from the examples of folders granted listing and describe it as excluded.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3 agent/Core/WindowsSandbox.cs:120: The changed Windows permissions have not been exercised in a sandbox or a build. When: With the default data path, profile and Local listings are withheld; the self-test must pass without them, and LLVM tools that resolve a real path must still start and link. Do: Run the Windows sandbox self-test and a real compile and link on a fresh default-path setup, then repeat the self-test after upgrading a setup with the old grants. Exercise both sandbox modes where available.

@fix can do L2.

Since the last review (on f0cae3a4eb)
Resolved: L1 (Skipping broad folders does not remove listing ACEs already granted by earlier versions.); L4 (It conflicts with its base branch: bring it up to date (@​fix or @​rebase try first).)
Still open: L2 (The safe-ancestor examples still include Local, although LOCALAPPDATA is excluded by WinHo…); L3 (The changed Windows permissions have not been exercised in a sandbox or a build.)

Checks: Still running: 5 checks.

Also noticed (1; not asked for, not blocking)
  • The migration silently skips ACL errors, so a stale grant can remain if permissions on an ancestor have changed since it was granted.
More: does it help, other systems, switches, what was read

Does it help: Unproven: the author reports successful builds, but no Windows sandbox self-test or game build exercising the permission change is reported.

Other systems: The shared preparation path affects both AppContainer and low-user Windows sandboxes, including resolved data paths. Linux is unaffected. A Windows run is still needed to check sandbox isolation and tool startup.

Switches: None.

Reviewed: 92230c2d8d against adde94bc90: Read the repository rules, the complete diff and commit, and the changed ACL, path-planning, sandbox and documentation sections; the large code and test files were only partially read. No pull request template or review checklist was found.; nothing run (a code review).

Checked and fine:

  • The migration covers lexical and resolved data paths and deduplicates their ancestors.
  • The ACL short-circuit avoids rewriting an ACL when the sandbox SID has no explicit allow or deny ACE.
  • The reported conflict is resolved.

Testing: The author reports successful agent and test-project builds. No tests were run during this review; CI is still running. Exercise both Windows sandbox modes, including an upgraded installation with stale grants, list_profile, tool startup and a build.

Overlaps and merge order: SafeAbove was merged in #180 before this change; the current base includes it.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The migration removes stale explicit grants for the sandbox SID when it can update the affected ACLs, but its effect on sandbox checks and a real Windows build has not been demonstrated. Recommend approval; not approved on the forge. The change revokes old broad-ancestor permissions during Windows sandbox preparation and adds an idempotent ACL check. It preserves the existing safe-ancestor grants, at the cost of inspecting the affected ACLs during preparation. **Nits (1)**: optional. - **L2** `docs/windows-clang.md:47`: The safe-ancestor examples still include Local, although LOCALAPPDATA is excluded by WinHost.TooWide. *When:* A maintainer diagnosing LLVM permissions is told those grants exist even though this change skips them on a fresh setup. **Do:** Remove Local from the examples of folders granted listing and describe it as excluded. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3** `agent/Core/WindowsSandbox.cs:120`: The changed Windows permissions have not been exercised in a sandbox or a build. *When:* With the default data path, profile and Local listings are withheld; the self-test must pass without them, and LLVM tools that resolve a real path must still start and link. **Do:** Run the Windows sandbox self-test and a real compile and link on a fresh default-path setup, then repeat the self-test after upgrading a setup with the old grants. Exercise both sandbox modes where available. `@fix` can do L2. **Since the last review** (on f0cae3a4ebdd) Resolved: L1 (Skipping broad folders does not remove listing ACEs already granted by earlier versions.); L4 (It conflicts with its base branch: bring it up to date (`@​fix` or `@​rebase` try first).) Still open: L2 (The safe-ancestor examples still include Local, although LOCALAPPDATA is excluded by WinHo…); L3 (The changed Windows permissions have not been exercised in a sandbox or a build.) **Checks:** Still running: 5 checks. <details> <summary>Also noticed (1; not asked for, not blocking)</summary> - The migration silently skips ACL errors, so a stale grant can remain if permissions on an ancestor have changed since it was granted. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven: the author reports successful builds, but no Windows sandbox self-test or game build exercising the permission change is reported. **Other systems:** The shared preparation path affects both AppContainer and low-user Windows sandboxes, including resolved data paths. Linux is unaffected. A Windows run is still needed to check sandbox isolation and tool startup. **Switches:** None. **Reviewed:** 92230c2d8d7d against adde94bc90ad: Read the repository rules, the complete diff and commit, and the changed ACL, path-planning, sandbox and documentation sections; the large code and test files were only partially read. No pull request template or review checklist was found.; nothing run (a code review). **Checked and fine:** - The migration covers lexical and resolved data paths and deduplicates their ancestors. - The ACL short-circuit avoids rewriting an ACL when the sandbox SID has no explicit allow or deny ACE. - The reported conflict is resolved. **Testing:** The author reports successful agent and test-project builds. No tests were run during this review; CI is still running. Exercise both Windows sandbox modes, including an upgraded installation with stale grants, list_profile, tool startup and a build. **Overlaps and merge order:** SafeAbove was merged in #180 before this change; the current base includes it. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Coordinator tests (pull_request) Blocked by required conditions
CI / Agent build and checks (pull_request) Blocked by required conditions
CI / Coordinator image (pull_request) Blocked by required conditions
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Beanstalk!179
No description provided.