fix(browse): grant Windows ACLs to token SID, not bare username#2170
Open
IntegriGit wants to merge 1 commit into
Open
fix(browse): grant Windows ACLs to token SID, not bare username#2170IntegriGit wants to merge 1 commit into
IntegriGit wants to merge 1 commit into
Conversation
restrictFilePermissions / restrictDirectoryPermissions passed os.userInfo().username straight to `icacls /grant`. On a domain-joined Windows host that also has a *local* account of the same login name, icacls resolves the bare name to the LOCAL account (e.g. HOST\user), not the domain account the process runs as (e.g. DOMAIN\user). Combined with `/inheritance:r`, the new single-entry ACL is granted to an account the process is NOT, locking it out of the .gstack state dir it just created. The browse daemon then can't create its lock/state file and startup fails with a misleading "Another instance is starting... Timed out." Fix: resolve the current process token SID via System32\whoami.exe (absolute path, so a shadowing Unix `whoami` on PATH can't hijack it) and grant `*<SID>`, which is immune to local-vs-domain name collisions. Fall back to USERDOMAIN\username, then bare username, if the SID lookup is unavailable. Cached per process. Adds a regression test asserting the resolved principal is a SID literal (*S-1-5-...) on Windows and a non-empty name-based fallback off-Windows. Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
browse/src/file-permissions.tshardens sensitive gstack state (auth/canary tokens, chat history, agent queue, device salt, per-tab security decisions) by breaking ACL inheritance and granting a single-entry ACL to the current user viaicacls. It resolved that user withos.userInfo().username— the bare login name.On a domain-joined Windows host that also has a local account of the same login name,
icacls /grant lmiller:...resolves the bare name to the local SAM account (HOST\lmiller), not the domain account the process actually runs as (DOMAIN\lmiller). Combined with/inheritance:r, the new ACL is granted to an account the process is not, locking it out of the.gstackstate directory it just created. The browse daemon then can't create its lock/state file and fails to start with a misleading:This reproduced reliably on a domain-joined Windows 11 box (
INTEGRIBILT\lmillerprocess vs. same-named localOFC01\lmiller).Fix
Add
currentUserIcaclsPrincipal():System32\whoami.exe /user /fo csv /nh, called by absolute path so a shadowing Unixwhoamiearlier onPATH(e.g. Git-for-Windows) can't hijack it and force the weaker fallback.icacls ... *S-1-5-…(SID literal), which is immune to local-vs-domain name collisions.USERDOMAIN\username, then bareusername, if the SID lookup is unavailable. Cached per process.Both
restrictFilePermissionsandrestrictDirectoryPermissionsnow use it instead of the bareos.userInfo().username. POSIX paths are unchanged.Tests
bun test browse/test/file-permissions.test.ts— 15 pass / 0 fail.Adds a regression test asserting the resolved principal is a SID literal (
*S-1-5-…) on Windows, and a non-empty name-based fallback off-Windows. Verified on a domain-joined Windows 11 host: the emittedicaclsgrant is now*S-1-5-21-…:(F)rather than a bare name.Co-Authored-By: Paperclip noreply@paperclip.ing