Repository navigation
fix(windows): align private-path ancestor ACL trust, diagnostics, and preflight - #682
oldwinter53 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Request changes (1 P1, 2 P2)
Scope: base main @ afa1c47d (branch is up to date), 2 commits, 14 files reviewed at bf6a83e9. Loaded ponytail-review (sections 1–3). I did not load coderbook or karpathy-guidelines; their review passes were applied from the skill instructions only. The review ran in a separate session.
Findings
P1
1. Unelevated administrators are treated as standard users, so Administrators-owned private paths are refused (packages/local-installation/src/windows-private.ts:110-117)
The new fast path in Test-Administrator returns $false when $identity.Groups has no S-1-5-32-544. .NET's WindowsIdentity.Groups returns only groups that are enabled and not deny-only. An administrator who runs without elevation has a UAC-filtered token, and in that token BUILTIN\Administrators is SE_GROUP_USE_FOR_DENY_ONLY. The group is therefore never in Groups for exactly the user that Test-LinkedTokenAdministrator exists to detect. That function is now unreachable through Test-Administrator.
- Failure scenario: the person once ran Linger or the installer elevated, so
~\.simplexai(or a private file in it) is owned byAdministrators. They then launch Desktop normally. The owner check at lines 211/235 callsTest-Administrator, gets$false, and throwsUNSAFE_OWNER. Setup now fails in the newprivate_pathspreflight and in the installer. Before this PR the same path was accepted, which is the behaviorpackages/local-installation/AGENTS.mddocuments ("Administrators enabled in the token or in the elevated token UAC links to it"). - Tests don't catch it. The native test at
windows-private.native.test.ts:341callsTest-LinkedTokenAdministratordirectly, so it skips the new pre-filter. CI also does not run the PowerShell native tests: the only Windows job,check (computer-go-windows), runs Go only. - Fix: delete the
Groupsshortcut (lines 110-117). A standard user'sGetTokenInformation(TokenLinkedToken)already fails and returns$false, and the stubs are now built in memory, so no compilation happens on that path anyway. If a fast path is still wanted, useTokenElevationType(limited vs. default) rather thanGroups. Add a test that runsTest-Administratoritself.
P2
2. The TypeScript SID classifiers are only used by tests and duplicate the PowerShell logic that actually runs (packages/local-installation/src/windows-private.ts:382-408)
isWindowsBuiltinAdminSid and isEligibleAdminMemberSid are exported, but git grep finds callers only in windows-private.test.ts:207-238. Production decisions come from the PowerShell Test-BuiltinAdminSid / Test-EligibleAdminMemberSid (lines 23-44), which no Linux test exercises. The unit tests therefore check a third copy of the rule (the other two are PowerShell and Go trusted_sid.go). That copy can drift from the PowerShell version while the tests stay green. Fix: delete both exports, their tests, and the isCanonicalUint32 / UINT32_TOKEN_PATTERN helpers they need. Cover the PowerShell functions in the Windows native test instead.
3. Diagnostics come from matching English PowerShell error prose (packages/local-installation/src/windows-private.ts:414-439)
classifyWindowsPrivateStderr regex-matches Method invocation is supported only on core types, Application Control, blocked by group policy, not recognized and similar text. The root AGENTS.md forbids keying behavior on third-party error prose. These messages are also localized, so on a Chinese, Japanese or German Windows install the classifier never fires and the user is back to a bare UNCHECKED, which is the case this PR sets out to fix. Fix: have the script emit a structured token as its first statement, for example $ExecutionContext.SessionState.LanguageMode written to stdout before anything that CLM blocks. Otherwise drop the stderr classification and keep only the worker=exit:<code> token.
Verified as fine
- Go/PowerShell parity of ancestor trust: owner checks trust user/SYSTEM/Administrators/TrustedInstaller/RID 500·512·519/eligible direct admin members (
trusted_sid.go:85-115withallowRuleOnly=false,windows-private.ts:244-247). ACE checks additionally trust CREATOR OWNER/OWNER RIGHTS and Codex sandbox SIDs (trusted_sid.go:110-114,windows-private.ts:262-266). Inherit-only and deny ACEs are skipped on both sides (privatefs_windows.go:280,windows-private.ts:258-259). - Broad groups (
S-1-1-0,S-1-5-11,S-1-5-32-545, RID 513/501) are rejected even when they appear in the admin-member set, becauseisEligibleAdminMemberSIDgates membership (trusted_sid.go:104; tests attrusted_sid_test.go:99-101). Go Windows tests ran incheck (computer-go-windows). NetLocalGroupGetMemberslevel 0 struct, paging onERROR_MORE_DATA, and buffer freeing are correct (privatefs_windows.go:337-381). The lookup is lazy, happens once perpinParentswalk, and fails closed to an empty set.- Private targets stay owner-only:
validateDescriptorand the PSverifystage are unchanged. - The
locationkind is non-destructive. It skips therepairandverifystages (windows-private.ts:273), walks to the nearest existing ancestor for a missing directory (lines 214-222), and fails closed withUNSAFE_TYPEon a missing drive. - The Desktop preflight runs only in
#install(setup and retry), not on#resume, so it adds no PowerShell start to a normal launch (local-server.ts:803,1224-1285). A home refusal keeps itscode/reason, so the setup page'sUNSAFE_PARENT_ACCESSbranch still works. A daemon-directory refusal is wrapped without them and so is not shown as an install-location refusal (local-server.ts:1273-1282,1452-1454; tests atlocal-server.test.ts:3111-3219). Desktop has no other in-processwindowsPrivatePathcaller that the?? errorfallback could mis-tag. - Failure output is allowlisted: reason codes, SID regex, a control-character-free ancestor path ≤512 chars, and stage/type/HRESULT patterns (
windows-private.ts:464-534). - No CJK in added lines or commit messages. No env vars, contracts or migrations changed. README and AGENTS docs are updated.
Unverified: the Reflection.Emit DefinePInvokeMethod stubs and the PowerShell NetLocalGroupGetMembers marshaling were not run on Windows by CI or by me. The PR body also reports the 11 native tests as skipped on Linux.
Process notes
bf6a83e9(test(desktop): stub private location preflight in Windows rename tests) only fixes tests that3ec59c53broke. Squash it into that commit, becausemaintakes rebase merges.
CI
Everything that ran passed: check (computer-go), check (computer-go-windows), check (desktop), check (packages), check (installer), repository-gate, CodeQL. The other checks were skipped by path filter. CI did not cover the PowerShell native tests (windows-private.native.test.ts only runs on win32, and no Windows Node job exists) or Go -race. This PR does not touch daemon concurrency. I ran no tests locally.
Automated review by Claude Code
Automated review of bf6a83e by Claude Code.
bf6a83e to
800c507
Compare
|
Addressed all review findings in squashed commit
|
There was a problem hiding this comment.
Approve (0 findings)
Follow-up on bf6a83e. Scope: base main, merge base afa1c47d; 1 commit, 14 files reviewed (full merge-base diff, plus the bf6a83e..800c507 delta of 4 files). Helper skills used: coderbook (§2, §3, §5), ponytail-review (§1–3), karpathy-guidelines (§2–3). Ran in a separate session.
Previous findings
- P1 Unelevated administrator treated as non-admin: Resolved.
packages/local-installation/src/windows-private.ts:103-112no longer reads$identity.Groups, which leaves out the deny-only Administrators group. WhenIsInRolefails, it now always callsTest-LinkedTokenAdministrator. For a standard user,GetTokenInformation(TokenLinkedToken)fails and the function returnsfalse(:85). The unit test asserts that$identity.Groupsis gone (windows-private.test.ts:38), and the native test calls bothTest-AdministratorandTest-LinkedTokenAdministrator. - P2 TS SID classifiers only used by tests: Resolved.
isWindowsBuiltinAdminSidandisEligibleAdminMemberSidand their tests are deleted.windows-private.native.test.ts:351-380now checks the production PowerShellTest-BuiltinAdminSid/Test-EligibleAdminMemberSiddirectly (RID 500/512 accepted, 513 andEveryonerejected, RID 1006 and Entra accepted). - P2 Diagnostics classified from English stderr prose: Resolved.
classifyWindowsPrivateStderr, stderr capture, and thestderrparameter are all removed. The worker now usesstdio: [..., "ignore"](:515). Both scripts check$ExecutionContext.SessionState.LanguageModebefore the preamble and report a structured{"code":"UNCHECKED","stage":"language_mode","errorType":<mode>}(:308-311,:336-339). Thewindows-private.test.tsCLM case shows it parsing tostage=language_mode, type=ConstrainedLanguage.
Findings
None.
Verified as fine
- CLM line from the worker reaches the caller.
executecallsensureWorker()and setsinstance.pendingin the same synchronous turn, before any stdout event can fire (windows-private.ts:651-675). So the startup__LINGER_ACL_ERR__:{...language_mode...}line goes to the pending request. The laterclosefinds no pending request, and the next call spawns a fresh worker. - The language-mode check comes before anything CLM blocks. It runs before
WINDOWS_PRIVATE_PREAMBLE, which holds the[Console]::*Encodingassignments and theReflection.Emitstubs (:9-15,:53-76). It uses only property reads, string concatenation,Write-Outputandexit. - Removing the stderr plumbing leaves nothing behind. No remaining references to
stderr,MAX_STDERR_BYTESorclassifyWindowsPrivateStderr(git grep).WorkerProcess.stderris gone and the fake worker matches the real interface. - Daemon-directory preflight is kept apart from install-location refusals.
local-server.ts:1258-1285wraps a daemon-directory failure in a plainErrorwith nocode/reason, sowindowsPrivateRefusal(error.refusal ?? error)(:1452) returnsundefined. The home check passes theWINDOWS_PRIVATE_PATH_UNSAFEerror through unchanged, sowindowsPrivateRefusal(windows-private.ts:803-815) still tags it.windowsPrivateLocationsendskind: "location", repair: false(:759-763). For a missing target, the script checks the nearest existing ancestor (:196,:265), so<userData>/computerneed not exist yet. - Go ancestor trust matches the PowerShell rules.
trusted_sid.go'sisWindowsBuiltinAdminSID/isEligibleAdminMemberSIDuse the same canonical-uint32 and RID rules asTest-BuiltinAdminSid/Test-EligibleAdminMemberSid. CREATOR OWNER, OWNER RIGHTS and the sandbox SIDs are allowed only on ACEs (allowRuleOnlySIDs), never as the owner (privatefs_windows.go:259-270). The admin-member and sandbox lookups are lazy and run at most once per walk (:75-88). IflocalAdminMemberSIDsfails, it returns an empty set, so validation fails closed. - No CJK in added lines or the commit message, and no merge commits.
Process notes
None. One commit, linked to a GitHub account, branch up to date with main.
CI
All required checks pass, including check (computer-go-windows), check (packages), check (desktop), check (installer) and repository-gate. Not covered by CI: windows-private.native.test.ts (Windows-only, skipIf(platform !== "win32")), so the PowerShell probe of Test-Administrator and the SID classifiers is unverified in CI and needs a Windows run. I did not run any tests myself.
Automated review by Claude Code
Automated review of 800c507 by Claude Code.
Summary
Fixes WHI-997: default Windows user home (
~\.simplexai) and%APPDATA%\Linger\computerpaths failing private-path validation with opaqueUNCHECKEDerrors, rejected built-in Administrator (RID 500) / local administrator / Codex sandbox ancestor SIDs, or late post-install daemon crashes.Changes
Eliminate inline
Add-TypeC# compilation and surface sanitized failure causes (packages/local-installation/src/windows-private.ts)Add-Type -TypeDefinition(csc.exetemp compilation, which fails under AV/WDAC/AppLocker or locked temp directories) inTest-LinkedTokenAdministratorwith pure in-memoryReflection.Emit(DefinePInvokeMethod).$ExecutionContext.SessionState.LanguageModecheck at script startup (before any .NET calls blocked by Constrained Language Mode) and configured UTF-8 stdout encoding.UNCHECKEDswallowing with strictly allowlisted structured diagnostics:ancestorpath and validatedsid(S-1-...).stage, exceptionerrorType, and 32-bit hexhresult(never raw exception prose or stderr text matching).worker=timeout|spawn:<errno>|exit:<code>|signal:<sig>|desync|stdin:<errno>|write:<errno>).windowsPrivateLocation(directory)(kind: "location",repair: false) matching the API shape used by#666.Align Windows ancestor ACL trust and reporting across installer (
windows-private.ts) and daemon (privatefs)apps/computer/local-daemon/internal/platform/privatefs/trusted_sid.go) and matching PowerShell helpers inwindows-private.ts:S-1-5-21-*-*-*-500), Domain Admins (-512), and Enterprise Admins (-519), as well as lazily queried direct localBUILTIN\Administratorsmembers (NetLocalGroupGetMemberslevel 0, filtered to individual/domain RID>= 1000or Entra IDS-1-12-1-*SIDs — explicitly excludingEveryone,Users,Authenticated Users,Domain Users, andGuest).windows-private.tsinto parity withprivatefs_windows.gofor Codex Windows sandbox principals (CodexSandboxUsersand%USERPROFILE%\.codex\cap_sid/%CODEX_HOME%\cap_sid) on ancestor access rules.FullControl/Everyone/ non-admin rejection.privatefs_windows.go(pinParentsandvalidateAncestorDescriptor) to include the exact offending ancestor path and SID in error messages.Pre-check
%APPDATA%\Linger\computeralongside the install home during Windows setup preflight (apps/desktop/src/main/index.ts,apps/desktop/src/main/local-server.ts)daemonDirectoryintoLocalServerModuleand validated bothhomeanddaemonDirectorynon-destructively in#install'spreparestep on Windows before fetching Node or unpacking.windowsPrivateRefusalfor home refusals while keeping daemon-directory refusals distinct from install-location refusals so setup does not suggest moving the install folder when<userData>/computerfails.Verification
cd apps/computer/local-daemon && go test -v ./internal/platform/privatefs/... && go vet ./...cd apps/computer/local-daemon && GOOS=windows GOARCH=amd64 go test -c -o /dev/null ./internal/platform/privatefs && GOOS=windows GOARCH=amd64 go vet ./internal/platform/privatefs/... && GOOS=windows GOARCH=amd64 go build ./...pnpm --filter @linger/local-installation typecheck && pnpm --filter @linger/local-installation lintpnpm --filter @linger/local-installation exec vitest run src/windows-private.test.ts src/windows-private-ancestors.test.ts src/windows-private.native.test.ts src/windows-state-security.test.ts(15/15 passed; 11 Windows-only native tests skipped on Linux)pnpm --filter @linger/desktop typecheck && pnpm --filter @linger/desktop lint && pnpm --filter @linger/desktop exec vitest run --config vitest.config.ts src/main/local-server.test.ts(171/171 passed)pnpm --filter @linger/linger-installer typecheck && pnpm --filter @linger/linger-installer lintpnpm env:inventory:checkpnpm exec commitlint --from origin/main --to HEADbash scripts/ci/check-changed-files.sh origin/main HEADRefs: WHI-997 (coordinated with #666 and #594 to avoid UI/inspect conflicts).