Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(lending): refuse another name for a hidden home entry (8.3 alias)
Bugfixer 267a5a7c93cc5
diff --git a/electron/lending-guards.node-test.mjs b/electron/lending-guards.node-test.mjsindex 25fc575d31..fc37e733c2 100644--- a/electron/lending-guards.node-test.mjs+++ b/electron/lending-guards.node-test.mjs@@ -1,13 +1,13 @@// A hostile or prompt-injected server against the real connector and executor.import assert from "node:assert/strict";import { test } from "node:test";-import { lstat, mkdtemp, mkdir, readFile, realpath, rm, stat, symlink, writeFile } from "node:fs/promises";+import { link, lstat, mkdtemp, mkdir, readFile, realpath, rm, stat, symlink, writeFile } from "node:fs/promises";import { readFileSync } from "node:fs";import { tmpdir } from "node:os";import path from "node:path";import { randomUUID } from "node:crypto";import { createComputerSharing, validSharedOperation } from "./computer-sharing.mjs";-import { executeSharedOperation, LENT_SCREEN_TOOLS } from "./shared-computer-access.mjs";+import { executeSharedOperation, homeSettingsTarget, LENT_SCREEN_TOOLS } from "./shared-computer-access.mjs";import { LENT_SCREEN_ARGUMENTS, lentScreenArguments } from "./lent-screen-tools.mjs";import { createLendingActivity } from "./lending-activity.mjs";import { helperMissing, SCREEN_LOCKED } from "./lent-screen-failures.mjs";@@ -469,3 +469,14 @@ test("direct executor: through the whole system drive, the home folder's hiddenawait run({ action: "write_file", path: inHome("Documents/plan.txt"), content: "fine" });assert.equal(await readFile(path.join(home, "Documents", "plan.txt"), "utf8"), "fine");});++test("another name for a hidden home entry (an 8.3 alias such as APPDAT~1, here a hard link) counts as that entry", async t => {+ const home = await realpath(await mkdtemp(path.join(tmpdir(), "omb-alias-home-")));+ t.after(() => rm(home, { recursive: true, force: true }));+ await writeFile(path.join(home, ".vimrc"), "set number\n");+ await link(path.join(home, ".vimrc"), path.join(home, "VIMRC~1"));+ await mkdir(path.join(home, "Documents"));+ await writeFile(path.join(home, "notes.txt"), "plain\n");+ for (const relative of ["VIMRC~1", "./VIMRC~1", ".bashrc", "AppData/Roaming/x.json"]) assert.equal(await homeSettingsTarget(home, relative), true, relative);+ for (const relative of ["notes.txt", "Documents/plan.txt", "NEW~1/x.txt", ""]) assert.equal(await homeSettingsTarget(home, relative), false, relative);+});diff --git a/electron/shared-computer-access.mjs b/electron/shared-computer-access.mjsindex 7401093770..ce76c4ebbe 100644--- a/electron/shared-computer-access.mjs+++ b/electron/shared-computer-access.mjs@@ -75,6 +75,22 @@ async function insideHomePath(target, home = os.homedir()) {return null;}+/** Whether `relative` (inside `home`) is one of home's hidden entries, Library or AppData. By name and by {dev, ino}, so+ * another name for the same entry (a Windows 8.3 alias such as APPDAT~1 or VIMRC~1) is refused as the entry is. */+export async function homeSettingsTarget(home, relative) {+ if (insideHomeSettings(relative)) return true;+ const first = relative.split("/").find(part => part && part !== ".");+ if (!first) return false;+ const sameEntry = async name => { const info = await fs.lstat(path.join(home, name), { bigint: true }); return `${info.dev}:${info.ino}`; };+ let identity;+ try { identity = await sameEntry(first); } catch (error) { if (absent(error)) return false; throw error; }+ for (const name of await fs.readdir(home)) {+ if (!insideHomeSettings(name)) continue;+ try { if ((await sameEntry(name)) === identity) return true; } catch (error) { if (!absent(error)) throw error; }+ }+ return false;+}+/** {dev, ino}, never path text; a root a fresh install has not created yet is skipped. */export async function protectedIdentities(roots) {const identities = new Set();@@ -327,11 +343,11 @@ export async function executeSharedOperation(grant, operation, signal, cua, lentconst remove = operation.action === "delete_file", changes = write || edit || append || remove;if (changes && folder.write !== true) throw new Error("This folder is read-only");if (changes && insideGitInternals(folder.path, operation.path ?? "")) throw new Error(GIT_INTERNALS);- if (changes && folder.home === true && insideHomeSettings(operation.path ?? "")) throw new Error(HOME_SETTINGS);+ if (changes && folder.home === true && await homeSettingsTarget(folder.path, operation.path ?? "")) throw new Error(HOME_SETTINGS);// The whole system drive holds the home folder too: the same files stay out of reach through it.if (changes && folder.system === true) {const inHome = await insideHomePath(target);- if (inHome !== null && insideHomeSettings(inHome)) throw new Error(HOME_SETTINGS);+ if (inHome !== null && await homeSettingsTarget(await fs.realpath(os.homedir()), inHome)) throw new Error(HOME_SETTINGS);}let data;if (write) {