fix(windows): grant icacls by SID, not unqualified username - #2479
Open
asizux2 wants to merge 1 commit into
Open
fix(windows): grant icacls by SID, not unqualified username#2479asizux2 wants to merge 1 commit into
asizux2 wants to merge 1 commit into
Conversation
An unqualified username is ambiguous. On a machine whose hostname equals the username, it does not resolve to the user account; icacls silently writes an ACE for the machine SID instead. Combined with /inheritance:r, the directory is left with a single ACE that matches nobody, so the process that just created it can no longer enumerate or write to it. In practice this means browse can never start on an affected machine: it bricks .gstack/ on first run, then reports "Another instance is starting the server" because acquireServerLock() returns null on the resulting EACCES. The real cause is invisible, since icacls reports success and stdio is ignored. Resolve the current user's SID and pass icacls the literal *<SID> form, which is immune to name-resolution ambiguity. Fall back to the domain-qualified name if the lookup fails. The SID lookup pins %SystemRoot%\System32\whoami.exe rather than a bare `whoami`, which under a bash-flavoured PATH resolves to the MSYS build and rejects /user. Without the pin the primary path would silently fail on Git Bash, one of the most common Windows setups for this tool. Tests assert the directory stays usable by the calling process after hardening. The existing Windows cases only asserted "does not throw", which this bug sails straight past. On the pre-fix code path 8 of 15 tests fail, several of them pre-existing. Refs garrytan#2478 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
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.
Fixes #2478.
The bug
restrictFilePermissions()/restrictDirectoryPermissions()pass an unqualified username toicacls:On a machine whose hostname equals the username, the bare name does not resolve to the user account.
icaclswrites an ACE for the machine SID instead, and because the same call passes/inheritance:r, the directory is left with a single ACE that matches nobody. The process that just created the directory can no longer enumerate or write to it.Observed on Windows 11, hostname
ESLAM, userESLAM\eslam:eslam(current behaviour)NTAccount.Translatethrows "Some or all identity references could not be translated"ESLAM\eslamS-1-5-21-<redacted>-1001whoami /userS-1-5-21-<redacted>-1001Net effect: browse can never start on an affected machine.
mkdirSecure()creates.gstack/, hardens it into inaccessibility, and the daemon's next act is writing a lockfile inside.acquireServerLock()returnsnullon the resultingEACCES, so the user sees:which points at a concurrency problem that does not exist.
icaclsreports success andstdio: 'ignore'discards its output, so nothing surfaces the real cause.The fix
Resolve the current user's SID and hand
icaclsthe literal*<SID>form, which is immune to name-resolution ambiguity. Fall back to the domain-qualified name if the lookup fails.One subtlety worth flagging for review: the SID lookup pins
%SystemRoot%\System32\whoami.exerather than calling a barewhoami. Under a bash-flavouredPATH(Git Bash / MSYS, extremely common for this tool on Windows) a barewhoamiresolves to the MSYS build, which rejects/user. I hit exactly that on the first test run: the lookup silently failed and the code fell through to the qualified-name fallback. The fallback is correct, but without the pin the primary path would almost never fire.Tests
The existing Windows cases only assert
not.toThrow(), which this bug sails straight past, sinceicaclsgenuinely succeeds while writing a useless ACE. The added cases assert the contract that actually broke: the directory stays usable by the calling process after hardening. Noicaclsoutput parsing, so no locale or version brittleness.Verified both directions on an affected machine:
Several of those 8 are pre-existing tests (
appendSecureFile,writeSecureFile). The suite could always have caught this; it just never ran anywhere the hostname matched the username.Risk
Behaviour is unchanged on POSIX (the
chmodpaths are untouched) and unchanged on Windows machines where the bare username already resolved correctly, since*<SID>and the resolved name name the same principal. The fallback preserves today's behaviour ifwhoami.exeis unavailable.