Skip to content

fix(browse): qualify icacls grants with USERDOMAIN (computer-name/username collision locks users out of state dirs) - #2388

Closed
Icandi40 wants to merge 1 commit into
garrytan:mainfrom
Icandi40:fix/icacls-qualified-username
Closed

Icandi40 wants to merge 1 commit into
garrytan:mainfrom
Icandi40:fix/icacls-qualified-username

Conversation

@Icandi40

Copy link
Copy Markdown

Bug

restrictFilePermissions / restrictDirectoryPermissions (browse/src/file-permissions.ts) pass the unqualified username to icacls:

icacls <path> /inheritance:r /grant:r <username>:(OI)(CI)(F)

When the computer name equals the username — common on personal machines (this repro: user hackdiva on a PC named HackDiva) — Windows' LookupAccountName resolves the bare name to the computer account: a bare machine SID (S-1-5-21-…, no RID) that no user token holds.

Combined with /inheritance:r, the directory ends up with a single ACE granting Full Control to a SID nobody has. The actual user — including the owner — is locked out of gstack's own state dir. And because these calls are documented as "idempotent, safe to re-apply", every browse invocation re-applies the lockout, so:

  • ~/.gstack and every project .gstack become unreadable/undeletable ("Permission denied" from both PowerShell and Git Bash),
  • the browse daemon can never acquire its lock ("Another instance is starting the server" forever),
  • repairs with icacls /reset or an unqualified /grant <username> silently fail the same way (same ambiguous lookup), which makes this maddening to diagnose — it presents as machine-level ACL corruption with a phantom "re-stamper".

Fix

Qualify the grantee with USERDOMAIN (the machine name for local accounts, the domain for domain accounts), making the lookup unambiguous:

icacls <path> /inheritance:r /grant:r HACKDIVA\hackdiva:(OI)(CI)(F)

One new helper (currentUserAccount()), used by both call sites. No behavior change on machines without the name collision.

Recovery note for affected users

Wedged dirs need the SID form (names stay ambiguous): takeown /f <dir> /r /d y then icacls <dir> /grant:r "*<your-user-SID>:(OI)(CI)F" /t (get the SID from whoami /user).

🤖 Generated with Claude Code

restrictFilePermissions/restrictDirectoryPermissions pass the unqualified
username to icacls. When the computer name equals the username (common on
personal machines: user 'hackdiva' on PC 'HackDiva'), LookupAccountName
resolves the bare name to the COMPUTER account — a bare machine SID that
no user token holds. Combined with /inheritance:r, the sole grant goes to
an unusable SID and the actual user is locked out of their own state dir.
Because these calls are idempotent-by-design, every browse invocation
re-applies the lockout, wedging .gstack dirs so hard that icacls /reset
and unqualified /grant repairs fail the same way.

Qualify the grantee with USERDOMAIN (the machine name for local accounts)
so the lookup is unambiguous.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@Icandi40

Icandi40 commented Jul 30, 2026 •

Copy link
Copy Markdown
Author

(Edited: a shell mangled the original comment, and the merge queue is maintainer-only anyway.) Ready for review whenever a maintainer has a moment — one-file fix, no behavior change on machines without the computer-name/username collision.

@trunk-io

trunk-io Bot commented Jul 30, 2026

Copy link
Copy Markdown

An error occurred while submitting your PR to the queue: Only users that are a part of this repo's Trunk organization or have write permissions to the repo can submit a PR to the queue

@garrytan

Copy link
Copy Markdown
Owner

Closing: this was absorbed or superseded on main by v1.67.0.0 or earlier (see the v1.67 tracker-wave receipts in PR #2604). Thank you!

@garrytan garrytan closed this Aug 17, 2026
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.

2 participants