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): name the path and the reason when a Windows private path check fails
Dongdong Chen537e2f07b530
diff --git a/packages/local-installation/src/windows-private.native.test.ts b/packages/local-installation/src/windows-private.native.test.tsindex 6d7b3fc4..cf8bfe71 100644--- a/packages/local-installation/src/windows-private.native.test.ts+++ b/packages/local-installation/src/windows-private.native.test.ts@@ -34,12 +34,12 @@ it.skipIf(process.platform !== "win32")(const junction = path.join(root, "link");await symlink(root, junction, "junction");await writeFile(path.join(root, "settings.json"), "{}");- await expect(windowsPrivatePath(junction, "directory")).rejects.toThrow(- /validation failed/,- );+ await expect(+ windowsPrivatePath(junction, "directory"),+ ).rejects.toMatchObject({ reason: "UNSAFE_TYPE", path: junction });await expect(windowsPrivatePath(path.join(junction, "settings.json"), "file"),- ).rejects.toThrow(/validation failed/);+ ).rejects.toMatchObject({ reason: "UNSAFE_PARENT_LINK" });},);it.skipIf(process.platform !== "win32")(@@ -67,9 +67,10 @@ it.skipIf(process.platform !== "win32")({ input: file, timeoutMs: 30000 },);expect(changed.code).toBe(0);- await expect(windowsPrivatePath(file, "file")).rejects.toThrow(- /validation failed/,- );+ await expect(windowsPrivatePath(file, "file")).rejects.toMatchObject({+ reason: "SHARED_ACCESS",+ path: file,+ });},);it.skipIf(process.platform !== "win32")(@@ -106,12 +107,12 @@ it.skipIf(process.platform !== "win32")().resolves.toBeUndefined();// A private target also owns future descendants, so broad inheritance on// the target remains forbidden even when it is inherit-only.- await expect(windowsPrivatePath(root, "directory")).rejects.toThrow(- /validation failed/,- );+ await expect(windowsPrivatePath(root, "directory")).rejects.toMatchObject({+ reason: "SHARED_ACCESS",+ });await mutate("None");- await expect(windowsPrivatePath(child, "directory")).rejects.toThrow(- /validation failed/,- );+ await expect(windowsPrivatePath(child, "directory")).rejects.toMatchObject({+ reason: "UNSAFE_PARENT_ACCESS",+ });},);diff --git a/packages/local-installation/src/windows-private.test.ts b/packages/local-installation/src/windows-private.test.tsindex 33011f08..b7b3f9fe 100644--- a/packages/local-installation/src/windows-private.test.ts+++ b/packages/local-installation/src/windows-private.test.ts@@ -1,3 +1,4 @@+import path from "node:path";import { expect, it, vi } from "vitest";import {windowsPrivatePath,@@ -19,10 +20,51 @@ it("sends paths through stdin and runs a fixed encoded ACL program", async () =>expect(WINDOWS_PRIVATE_SCRIPT).toContain("AccessControlSections]::Access");});it("fails closed without disclosing command diagnostics", async () => {- const run = vi.fn().mockResolvedValue({ code: 1, stderr: "sensitive path" });+ const run = vi+ .fn()+ .mockResolvedValue({ code: 1, stdout: "", stderr: "sensitive path" });+ const error = await windowsPrivatePath("private", "file", false, run).catch(+ (failure: unknown) => failure as Error,+ );+ expect(error?.message).toMatch(/^Windows private path validation failed/);+ expect(error?.message).not.toContain("sensitive");+ expect(error).toMatchObject({+ code: "WINDOWS_PRIVATE_PATH_UNSAFE",+ reason: "UNCHECKED",+ });+});+it("names the path and why it is not private", async () => {+ const file =+ "C:\\Users\\person\\.simplexai\\instances\\desktop\\native.env.1.tmp";+ const owned = vi+ .fn()+ .mockResolvedValue({ code: 1, stdout: "UNSAFE_OWNER", stderr: "" });+ const error = await windowsPrivatePath(file, "file", false, owned).catch(+ (failure: unknown) => failure as Error,+ );+ expect(error).toMatchObject({+ code: "WINDOWS_PRIVATE_PATH_UNSAFE",+ reason: "UNSAFE_OWNER",+ path: path.resolve(file),+ });+ expect(error?.message).toContain(path.resolve(file));+ expect(error?.message).toContain("owned by another account");+ // Only the script's fixed codes pass; anything else is unchecked.+ const other = vi.fn().mockResolvedValue({+ code: 1,+ stdout: "Access denied to C:\\x",+ stderr: "",+ });await expect(- windowsPrivatePath("private", "file", false, run),- ).rejects.toThrow("Windows private path validation failed");+ windowsPrivatePath(file, "file", false, other),+ ).rejects.toMatchObject({ reason: "UNCHECKED" });+});+it("gives every failure in the ACL program a fixed reason code", () => {+ const thrown = [...WINDOWS_PRIVATE_SCRIPT.matchAll(/throw '([^']*)'/g)].map(+ (match) => match[1],+ );+ expect(thrown.length).toBeGreaterThan(5);+ for (const code of thrown) expect(code).toMatch(/^[A-Z][A-Z_]+$/);});it("ignores inherit-only ACEs only for effective ancestor permissions", () => {const ancestors = WINDOWS_PRIVATE_SCRIPT.slice(@@ -36,5 +78,5 @@ it("ignores inherit-only ACEs only for effective ancestor permissions", () => {"$rule.PropagationFlags -band [Security.AccessControl.PropagationFlags]::InheritOnly",);expect(target).not.toContain("PropagationFlags");- expect(target).toContain("Non-private permissions");+ expect(target).toContain("SHARED_ACCESS");});diff --git a/packages/local-installation/src/windows-private.ts b/packages/local-installation/src/windows-private.tsindex c5580877..e1374ccf 100644--- a/packages/local-installation/src/windows-private.ts+++ b/packages/local-installation/src/windows-private.ts@@ -11,22 +11,22 @@ try {$sid = [Security.Principal.WindowsIdentity]::GetCurrent().User$system = 'S-1-5-18'; $admins = 'S-1-5-32-544'$item = Get-Item -LiteralPath $request.path -Force- if (($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -or ($item.PSIsContainer -ne ($request.kind -eq 'directory'))) { throw 'Unsafe type' }+ if (($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -or ($item.PSIsContainer -ne ($request.kind -eq 'directory'))) { throw 'UNSAFE_TYPE' }$acl = Get-Acl -LiteralPath $item.FullName- if ($acl.GetOwner([Security.Principal.SecurityIdentifier]).Value -ne $sid.Value) { throw 'Unsafe owner' }+ if ($acl.GetOwner([Security.Principal.SecurityIdentifier]).Value -ne $sid.Value) { throw 'UNSAFE_OWNER' }$parent = $item.Directoryif ($item.PSIsContainer) { $parent = $item.Parent }while ($parent) {- if ($parent.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw 'Unsafe parent link' }+ if ($parent.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw 'UNSAFE_PARENT_LINK' }$parentAcl = Get-Acl -LiteralPath $parent.FullName$owner = $parentAcl.GetOwner([Security.Principal.SecurityIdentifier]).Value- if ($owner -notin @($sid.Value, $system, $admins, 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464')) { throw 'Unsafe parent owner' }+ if ($owner -notin @($sid.Value, $system, $admins, 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464')) { throw 'UNSAFE_PARENT_OWNER' }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 permissions' }+ ($rule.FileSystemRights -band [Security.AccessControl.FileSystemRights]'Delete,DeleteSubdirectoriesAndFiles,ChangePermissions,TakeOwnership')) { throw 'UNSAFE_PARENT_ACCESS' }}$parent = $parent.Parent}@@ -44,17 +44,22 @@ try {if ($PSVersionTable.PSEdition -eq 'Core') { [IO.FileSystemAclExtensions]::SetAccessControl($item, $acl) } else { $item.SetAccessControl($acl) }$acl = Get-Acl -LiteralPath $item.FullName}- if ($request.kind -eq 'directory' -and !$acl.AreAccessRulesProtected) { throw 'Inherited private permissions' }+ if ($request.kind -eq 'directory' -and !$acl.AreAccessRulesProtected) { throw 'INHERITED_ACCESS' }$currentAllowed = $falseforeach ($rule in $acl.GetAccessRules($true, $true, [Security.Principal.SecurityIdentifier])) {if ($rule.AccessControlType -eq 'Allow') {- if ($rule.IdentityReference.Value -notin @($sid.Value, $system)) { throw 'Non-private permissions' }+ if ($rule.IdentityReference.Value -notin @($sid.Value, $system)) { throw 'SHARED_ACCESS' }if ($rule.IdentityReference.Value -eq $sid.Value) { $currentAllowed = $true }}}- if (!$currentAllowed) { throw 'Missing owner access' }+ if (!$currentAllowed) { throw 'MISSING_OWNER_ACCESS' }exit 0-} catch { exit 1 }+} catch {+ # Only this program's own reason codes leave it; never a system message.+ $code = [string]$_.Exception.Message+ if ($code -cmatch '^[A-Z][A-Z_]+$') { [Console]::Out.Write($code) }+ exit 1+}`;export async function windowsPrivatePath(file: string,@@ -82,8 +87,35 @@ export async function windowsPrivatePath(timeoutMs: 30000,},);- if (result.code !== 0)- throw new Error(- "Windows private path validation failed; use a current-user owned local directory without links or shared access.",+ if (result.code !== 0) {+ const reason: WindowsPrivateReason = Object.hasOwn(+ WINDOWS_PRIVATE_REASONS,+ result.stdout.trim(),+ )+ ? (result.stdout.trim() as WindowsPrivateReason)+ : "UNCHECKED";+ const target = path.resolve(file);+ throw Object.assign(+ new Error(+ `Windows private path validation failed: ${target} ${WINDOWS_PRIVATE_REASONS[reason]}. Use a current-user owned local directory without links or shared access.`,+ ),+ { code: WINDOWS_PRIVATE_PATH_UNSAFE, reason, path: target },);+ }}+/** The code of an error from windowsPrivatePath; its reason says why. */+export const WINDOWS_PRIVATE_PATH_UNSAFE = "WINDOWS_PRIVATE_PATH_UNSAFE";+// The ACL program's reason codes, worded for the error message.+const WINDOWS_PRIVATE_REASONS = {+ UNSAFE_TYPE: "is a link, or not the expected file or folder",+ UNSAFE_OWNER:+ "is owned by another account, such as Administrators after Linger ran as administrator",+ 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",+ 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",+ UNCHECKED: "could not be checked",+} as const;+export type WindowsPrivateReason = keyof typeof WINDOWS_PRIVATE_REASONS;