Skip to content

fix(windows): align private-path ancestor ACL trust, diagnostics, and preflight - #682

Open
oldwinter53 wants to merge 1 commit into
mainfrom
oldwinter53/fix-whi-997-win-acl
Open

oldwinter53 wants to merge 1 commit into
mainfrom
oldwinter53/fix-whi-997-win-acl

Conversation

@oldwinter53

@oldwinter53 oldwinter53 commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Fixes WHI-997: default Windows user home (~\.simplexai) and %APPDATA%\Linger\computer paths failing private-path validation with opaque UNCHECKED errors, rejected built-in Administrator (RID 500) / local administrator / Codex sandbox ancestor SIDs, or late post-install daemon crashes.

Changes

  1. Eliminate inline Add-Type C# compilation and surface sanitized failure causes (packages/local-installation/src/windows-private.ts)

    • Replaced Add-Type -TypeDefinition (csc.exe temp compilation, which fails under AV/WDAC/AppLocker or locked temp directories) in Test-LinkedTokenAdministrator with pure in-memory Reflection.Emit (DefinePInvokeMethod).
    • Added a language-agnostic $ExecutionContext.SessionState.LanguageMode check at script startup (before any .NET calls blocked by Constrained Language Mode) and configured UTF-8 stdout encoding.
    • Replaced bare UNCHECKED swallowing with strictly allowlisted structured diagnostics:
      • Ancestor and target refusals report the offending ancestor path and validated sid (S-1-...).
      • Unexpected PowerShell exceptions report sanitized stage, exception errorType, and 32-bit hex hresult (never raw exception prose or stderr text matching).
      • The persistent worker reports structured lifecycle diagnostics (worker=timeout|spawn:<errno>|exit:<code>|signal:<sig>|desync|stdin:<errno>|write:<errno>).
    • Added non-destructive windowsPrivateLocation(directory) (kind: "location", repair: false) matching the API shape used by #666.
  2. Align Windows ancestor ACL trust and reporting across installer (windows-private.ts) and daemon (privatefs)

    • Added pure cross-platform SID helpers (apps/computer/local-daemon/internal/platform/privatefs/trusted_sid.go) and matching PowerShell helpers in windows-private.ts:
      • Ancestor owners and replace-rights ACEs now trust canonical built-in Administrator (S-1-5-21-*-*-*-500), Domain Admins (-512), and Enterprise Admins (-519), as well as lazily queried direct local BUILTIN\Administrators members (NetLocalGroupGetMembers level 0, filtered to individual/domain RID >= 1000 or Entra ID S-1-12-1-* SIDs — explicitly excluding Everyone, Users, Authenticated Users, Domain Users, and Guest).
      • Brought windows-private.ts into parity with privatefs_windows.go for Codex Windows sandbox principals (CodexSandboxUsers and %USERPROFILE%\.codex\cap_sid / %CODEX_HOME%\cap_sid) on ancestor access rules.
      • Kept private targets themselves strictly owner-only and preserved volume-root FullControl / Everyone / non-admin rejection.
    • Updated privatefs_windows.go (pinParents and validateAncestorDescriptor) to include the exact offending ancestor path and SID in error messages.
  3. Pre-check %APPDATA%\Linger\computer alongside the install home during Windows setup preflight (apps/desktop/src/main/index.ts, apps/desktop/src/main/local-server.ts)

    • Wired daemonDirectory into LocalServerModule and validated both home and daemonDirectory non-destructively in #install's prepare step on Windows before fetching Node or unpacking.
    • Preserved windowsPrivateRefusal for home refusals while keeping daemon-directory refusals distinct from install-location refusals so setup does not suggest moving the install folder when <userData>/computer fails.

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 lint
  • pnpm --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 lint
  • pnpm env:inventory:check
  • pnpm exec commitlint --from origin/main --to HEAD
  • bash scripts/ci/check-changed-files.sh origin/main HEAD

Refs: WHI-997 (coordinated with #666 and #594 to avoid UI/inspect conflicts).

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by Administrators. They then launch Desktop normally. The owner check at lines 211/235 calls Test-Administrator, gets $false, and throws UNSAFE_OWNER. Setup now fails in the new private_paths preflight and in the installer. Before this PR the same path was accepted, which is the behavior packages/local-installation/AGENTS.md documents ("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:341 calls Test-LinkedTokenAdministrator directly, 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 Groups shortcut (lines 110-117). A standard user's GetTokenInformation(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, use TokenElevationType (limited vs. default) rather than Groups. Add a test that runs Test-Administrator itself.

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-115 with allowRuleOnly=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, because isEligibleAdminMemberSID gates membership (trusted_sid.go:104; tests at trusted_sid_test.go:99-101). Go Windows tests ran in check (computer-go-windows).
  • NetLocalGroupGetMembers level 0 struct, paging on ERROR_MORE_DATA, and buffer freeing are correct (privatefs_windows.go:337-381). The lookup is lazy, happens once per pinParents walk, and fails closed to an empty set.
  • Private targets stay owner-only: validateDescriptor and the PS verify stage are unchanged.
  • The location kind is non-destructive. It skips the repair and verify stages (windows-private.ts:273), walks to the nearest existing ancestor for a missing directory (lines 214-222), and fails closed with UNSAFE_TYPE on 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 its code/reason, so the setup page's UNSAFE_PARENT_ACCESS branch 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 at local-server.test.ts:3111-3219). Desktop has no other in-process windowsPrivatePath caller that the ?? error fallback 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 that 3ec59c53 broke. Squash it into that commit, because main takes 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.

@oldwinter53
oldwinter53 force-pushed the oldwinter53/fix-whi-997-win-acl branch from bf6a83e to 800c507 Compare November 24, 2026 19:38
@oldwinter53

oldwinter53 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Addressed all review findings in squashed commit 800c5078:

  1. P1 (Test-Administrator): Removed the WindowsIdentity.Groups pre-filter so UAC-filtered unelevated administrators reach Test-LinkedTokenAdministrator as intended, and expanded windows-private.native.test.ts to exercise Test-Administrator directly alongside Test-LinkedTokenAdministrator.
  2. P2 (duplicate TS SID classifiers): Removed unused isWindowsBuiltinAdminSid / isEligibleAdminMemberSid exports and their TS-only duplicates; moved PowerShell Test-BuiltinAdminSid / Test-EligibleAdminMemberSid assertions into windows-private.native.test.ts while Go trusted_sid_test.go covers the cross-platform Go helpers.
  3. P2 (stderr prose matching): Removed classifyWindowsPrivateStderr and stderr piping; added a language-agnostic $ExecutionContext.SessionState.LanguageMode structured check at script startup while keeping structured worker lifecycle codes (worker=exit:<code>, worker=spawn:<errno>, worker=timeout, worker=desync).
  4. Commit hygiene: Squashed the follow-up test fix into a single clean commit on main.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-112 no longer reads $identity.Groups, which leaves out the deny-only Administrators group. When IsInRole fails, it now always calls Test-LinkedTokenAdministrator. For a standard user, GetTokenInformation(TokenLinkedToken) fails and the function returns false (:85). The unit test asserts that $identity.Groups is gone (windows-private.test.ts:38), and the native test calls both Test-Administrator and Test-LinkedTokenAdministrator.
  • P2 TS SID classifiers only used by tests: Resolved. isWindowsBuiltinAdminSid and isEligibleAdminMemberSid and their tests are deleted. windows-private.native.test.ts:351-380 now checks the production PowerShell Test-BuiltinAdminSid / Test-EligibleAdminMemberSid directly (RID 500/512 accepted, 513 and Everyone rejected, RID 1006 and Entra accepted).
  • P2 Diagnostics classified from English stderr prose: Resolved. classifyWindowsPrivateStderr, stderr capture, and the stderr parameter are all removed. The worker now uses stdio: [..., "ignore"] (:515). Both scripts check $ExecutionContext.SessionState.LanguageMode before the preamble and report a structured {"code":"UNCHECKED","stage":"language_mode","errorType":<mode>} (:308-311, :336-339). The windows-private.test.ts CLM case shows it parsing to stage=language_mode, type=ConstrainedLanguage.

Findings

None.

Verified as fine

  • CLM line from the worker reaches the caller. execute calls ensureWorker() and sets instance.pending in 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 later close finds 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]::*Encoding assignments and the Reflection.Emit stubs (:9-15, :53-76). It uses only property reads, string concatenation, Write-Output and exit.
  • Removing the stderr plumbing leaves nothing behind. No remaining references to stderr, MAX_STDERR_BYTES or classifyWindowsPrivateStderr (git grep). WorkerProcess.stderr is gone and the fake worker matches the real interface.
  • Daemon-directory preflight is kept apart from install-location refusals. local-server.ts:1258-1285 wraps a daemon-directory failure in a plain Error with no code/reason, so windowsPrivateRefusal(error.refusal ?? error) (:1452) returns undefined. The home check passes the WINDOWS_PRIVATE_PATH_UNSAFE error through unchanged, so windowsPrivateRefusal (windows-private.ts:803-815) still tags it. windowsPrivateLocation sends kind: "location", repair: false (:759-763). For a missing target, the script checks the nearest existing ancestor (:196, :265), so <userData>/computer need not exist yet.
  • Go ancestor trust matches the PowerShell rules. trusted_sid.go's isWindowsBuiltinAdminSID / isEligibleAdminMemberSID use the same canonical-uint32 and RID rules as Test-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). If localAdminMemberSIDs fails, 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.

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