Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(local-installation): accept a folder directly on a Windows data drive
Kilyncca827c228e2
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex 771b8ac5..63df2675 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -11,6 +11,16 @@ stop unrelated processes, pull mutable images, or delete volumes as recovery.Every installation runs natively from a Linger source checkout; Docker is notused.+On Windows `windowsPrivatePath` makes a private path owner-only and refuses it+when another account could put a different folder in its place: an ancestor+that is a link, that another account owns, or that grants another account the+right to replace a child, change permissions, or take ownership. Delete on an+ancestor counts as well, because its holder can rename that folder, except on+a volume root, which can be neither renamed nor removed. A folder directly on+a data drive with the stock root ACL therefore passes, and a folder nested in+one that inherits Modify for Authenticated Users does not. The Daemon's+`privatefs` treats the volume root the same way.+`atomicPrivate` closes and removes its temporary file on failed writes orsyncs as well as failed publication. A failed replacement keeps the previousprivate file available, without leaving partial configuration copies behind.diff --git a/packages/local-installation/src/windows-private-ancestors.test.ts b/packages/local-installation/src/windows-private-ancestors.test.tsnew file mode 100644index 00000000..ffa520fd--- /dev/null+++ b/packages/local-installation/src/windows-private-ancestors.test.ts@@ -0,0 +1,58 @@+import { describe, expect, it } from "vitest";+import { WINDOWS_PRIVATE_SCRIPT } from "./windows-private.js";++// PowerShell does not run on every development machine, so these tests read+// the rights the ancestor rule names out of the fixed script. Get-Acl, the+// owner check and the walk itself run only in windows-private.native.test.ts+// on Windows.+const ANCESTORS = WINDOWS_PRIVATE_SCRIPT.slice(+ WINDOWS_PRIVATE_SCRIPT.indexOf("while ($parent)"),+ WINDOWS_PRIVATE_SCRIPT.indexOf("if ($request.repair)"),+);+const names = (pattern: RegExp) =>+ (pattern.exec(ANCESTORS)?.[1] ?? "").split(",").filter(Boolean);+const EVERYWHERE = names(/\$replace = '([A-Za-z,]+)'/);+const BELOW_ROOT = names(+ /if \(\$parent\.Parent\) \{ \$replace = "([A-Za-z,]+),\$replace" \}/,+);+const TRUSTED_INSTALLER =+ "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464";++// System.Security.AccessControl.FileSystemRights values the script names.+const RIGHTS: Record<string, number> = {+ DeleteSubdirectoriesAndFiles: 0x40,+ Delete: 0x10000,+ ChangePermissions: 0x40000,+ TakeOwnership: 0x80000,+};+const mask = (rights: string[]) =>+ rights.reduce((bits, right) => {+ const value = RIGHTS[right];+ if (value === undefined) throw new Error(`Unknown right ${right}`);+ return bits | value;+ }, 0);+// Modify, the right Windows gives Authenticated Users on every data drive it+// formats, and which folders made on that drive inherit.+const MODIFY = 0x1301bf;++describe("the ancestor rule in the fixed ACL program", () => {+ it("counts Delete only on a folder that has a parent", () => {+ expect(EVERYWHERE).toEqual([+ "DeleteSubdirectoriesAndFiles",+ "ChangePermissions",+ "TakeOwnership",+ ]);+ expect(BELOW_ROOT).toEqual(["Delete"]);+ expect(ANCESTORS).toContain(+ "[Security.AccessControl.FileSystemRights]$replace",+ );+ expect(ANCESTORS).toContain(+ `-notin @($sid.Value, $system, $admins, 'S-1-3-0', '${TRUSTED_INSTALLER}')`,+ );+ });++ it("lets others hold Modify on a data drive's root but not on a folder in it", () => {+ expect(MODIFY & mask(EVERYWHERE)).toBe(0);+ expect(MODIFY & mask([...BELOW_ROOT, ...EVERYWHERE])).toBe(RIGHTS.Delete);+ });+});diff --git a/packages/local-installation/src/windows-private.ts b/packages/local-installation/src/windows-private.tsindex 7158932d..61805c00 100644--- a/packages/local-installation/src/windows-private.ts+++ b/packages/local-installation/src/windows-private.ts@@ -63,12 +63,19 @@ try {$parentAcl = Get-Acl -LiteralPath $parent.FullName$owner = $parentAcl.GetOwner([Security.Principal.SecurityIdentifier]).Valueif ($owner -notin @($sid.Value, $system, $admins, 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464')) { throw 'UNSAFE_PARENT_OWNER' }+ # An ancestor is unsafe when another account can put a different folder+ # where the private one is. Delete lets its holder rename or remove the+ # folder that grants it; a volume root can be neither, and its stock ACL+ # grants Delete to Authenticated Users. Replacing a child of the root or+ # rewriting the root's ACL stays refused.+ $replace = 'DeleteSubdirectoriesAndFiles,ChangePermissions,TakeOwnership'+ if ($parent.Parent) { $replace = "Delete,$replace" }foreach ($rule in $parentAcl.GetAccessRules($true, $true, [Security.Principal.SecurityIdentifier])) {# InheritOnly ACEs do not authorize mutation of this ancestor. They are# still checked below when present on the private target itself.if ($rule.PropagationFlags -band [Security.AccessControl.PropagationFlags]::InheritOnly) { continue }if ($rule.AccessControlType -eq 'Allow' -and $rule.IdentityReference.Value -notin @($sid.Value, $system, $admins, 'S-1-3-0', 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464') -and- ($rule.FileSystemRights -band [Security.AccessControl.FileSystemRights]'Delete,DeleteSubdirectoriesAndFiles,ChangePermissions,TakeOwnership')) { throw 'UNSAFE_PARENT_ACCESS' }+ ($rule.FileSystemRights -band [Security.AccessControl.FileSystemRights]$replace)) { throw 'UNSAFE_PARENT_ACCESS' }}$parent = $parent.Parent}@@ -153,7 +160,8 @@ const WINDOWS_PRIVATE_REASONS = {UNSAFE_OWNER: "is owned by another account",UNSAFE_PARENT_LINK: "is inside a linked folder",UNSAFE_PARENT_OWNER: "is inside a folder another account owns",- UNSAFE_PARENT_ACCESS: "is inside a folder other accounts may change",+ UNSAFE_PARENT_ACCESS:+ "is inside a folder other accounts on this computer can rename or replace",INHERITED_ACCESS: "takes its permissions from its parent folder",SHARED_ACCESS: "is shared with other accounts",MISSING_OWNER_ACCESS: "does not give your account access",