Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Workspace backup: judge links into a followed top-level folder the same whatever the names
AdityaUmale413ce507819c
diff --git a/server/workspace-backup-policy.ts b/server/workspace-backup-policy.tsindex a926af42fc..dd81378885 100644--- a/server/workspace-backup-policy.ts+++ b/server/workspace-backup-policy.ts@@ -141,7 +141,8 @@ export function carriedTwice(followed: readonly FollowedTopLevelLink[], target:}/** The top-level items of the data folder `root` (its real path) that link to a place outside it, as the backup follows- * them. A dangling link, or one to a folder holding `root`, is left out here; the backup itself refuses both. */+ * them. Read before the walk, so a link into one of them is judged the same whatever the names sort like. A dangling+ * link, or one to a folder holding `root`, is left out here; the backup itself refuses both. */export function topLevelLinksOut(root: string): FollowedTopLevelLink[] {const links: FollowedTopLevelLink[] = [];for (const name of readdirSync(root)) {diff --git a/server/workspace-backup.test.ts b/server/workspace-backup.test.tsindex 6c75222afb..81c7b5d8f4 100644--- a/server/workspace-backup.test.ts+++ b/server/workspace-backup.test.ts@@ -702,6 +702,20 @@ describe("encrypted full workspace backups", () => {await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toMatchObject({ errorKey: "serverError.backup.recursiveLink" });});+ it("judges a bot folder's link into a linked top-level folder the same whatever that folder is called", async () => {+ const kind = process.platform === "win32" ? "junction" : "dir";+ for (const name of ["aa-store", "zz-store"]) {+ const root = directory();+ const drive = directory();+ mkdirSync(join(drive, "store", "notes"), { recursive: true });+ writeFileSync(join(drive, "store", "notes", "a.md"), "# A");+ symlinkSync(join(drive, "store"), join(root, name), kind);+ mkdirSync(join(root, "workspaces", "ws"), { recursive: true });+ symlinkSync(join(drive, "store", "notes"), join(root, "workspaces", "ws", "notes"), kind);+ await expect(createWorkspaceBackup(root, { password: PASSWORD }), name).rejects.toThrow(`user-created symbolic link; replace it with regular files first: workspaces/ws/notes`);+ }+ });+it("refuses provider authentication storage reached through a top-level link, and still follows unrelated linked folders", async () => {const root = directory();const drive = directory();diff --git a/server/workspace-backup.ts b/server/workspace-backup.tsindex f3446176e8..f42a1363e7 100644--- a/server/workspace-backup.ts+++ b/server/workspace-backup.ts@@ -316,7 +316,8 @@ export async function createWorkspaceBackup(dataDir: string, options: CreateWorkexport async function createWorkspaceBackupSnapshot(dataDir: string, options: CreateWorkspaceBackupOptions, jobId?: string): Promise<CreatedWorkspaceBackup> {if (Object.hasOwn(options, "credentials")) throw new Error("Workspace backups do not transfer credentials.");- assertLocalAuthOutsideSnapshot(dataDir, topLevelLinksOut(realpathSync(dataDir)));+ const linksOut = topLevelLinksOut(realpathSync(dataDir)), walked = linksOut.filter((link) => !excluded(link.name) && !LEGACY_SIDECARS.has(link.name));+ assertLocalAuthOutsideSnapshot(dataDir, linksOut);const salt = randomBytes(16);const key = await passwordKey(options.password, salt);const job = newJob(dataDir, jobId);@@ -331,8 +332,7 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Crlet skippedDependencies = 0;let skippedWorkLinks = 0;let copiedLinks = 0;- const leftLinks: string[] = [], leftProfiles: string[] = [];- const moved: FollowedTopLevelLink[] = [];+ const leftLinks: string[] = [], leftProfiles: string[] = [], moved: FollowedTopLevelLink[] = [];try {const root = realpathSync(dataDir);await snapshotDatabases(root, snapshot);@@ -375,7 +375,7 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Cr// named in the backup's note; anywhere else it still stops the backup.const leave = path.startsWith("workspaces/");try { target = realpathSync(source); } catch { if (leave) { leftLinks.push(path); continue; } throw new Error(`Cannot back up dangling symbolic link: ${path}`); }- const rel = dataRelativePath(root, moved, target);+ const rel = dataRelativePath(root, prefix ? walked : [], target);const followed = rel === undefined && !prefix;if (!followed) {if (rel === undefined) { if (leave) { leftLinks.push(path); continue; } throw new Error(`Cannot back up symbolic link outside the workspace: ${path}`); }