Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(skill-burger): refuse a file name the folders cannot store as an ordinary file
DeryFerd74120337cbb6
diff --git a/server/skill-burger/executors.test.ts b/server/skill-burger/executors.test.tsindex 0f551f07fc..f9b929109e 100644--- a/server/skill-burger/executors.test.ts+++ b/server/skill-burger/executors.test.ts@@ -62,6 +62,22 @@ describe("where a Skill Burger's steps run", () => {}});+ it("refuses a file name the folders cannot store as an ordinary file", async () => {+ const cwd = folder();+ try {+ const exec = createExecutors({ botId: "b", cwd, internal: async () => ({ ok: false, body: {} }) });+ // A Windows device name opens the device, stores nothing, and the step would still report success.+ expect(await exec.file({ path: "NUL", content: "x", signal: signal() })).toMatchObject({ ok: false });+ expect(await exec.file({ path: "notes/COM1.txt", content: "x", signal: signal() })).toMatchObject({ ok: false });+ // An NTFS alternate stream keeps the bytes out of the person's view of the file.+ expect(await exec.file({ path: "report.txt:notes", content: "x", signal: signal() })).toMatchObject({ ok: false });+ // An ordinary name in an ordinary folder still lands.+ expect(await exec.file({ path: "notes/report.txt", content: "x", signal: signal() })).toMatchObject({ ok: true });+ } finally {+ rmSync(cwd, { recursive: true, force: true });+ }+ });+it.skipIf(process.platform === "win32")("runs a command as the bot, reading its inputs from OMB_ARG_ variables, and stops one that says too much", async () => {const cwd = folder();const exec = createExecutors({ botId: "b", cwd, internal: async () => ({ ok: false, body: {} }) });diff --git a/server/skill-burger/executors.ts b/server/skill-burger/executors.tsindex a4b3c91130..a54714f6c3 100644--- a/server/skill-burger/executors.ts+++ b/server/skill-burger/executors.ts@@ -9,10 +9,12 @@ import { dirname, isAbsolute, relative, resolve as resolvePath, sep } from "nodeimport { appToolCall } from "../connector-app-tools.ts";import { toolData } from "../connected-reads.ts";import { killCliTree, spawnCli } from "../procs.ts";+import { unsafeFileNameProblem } from "../skill-folder.ts";import type { ExecResult, StepExecutors } from "./runner.ts";const MULTI_EXECUTE = "COMPOSIO_MULTI_EXECUTE_TOOL";const FILE_OUTSIDE = "a saved step writes files only inside this conversation's folder";+const FILE_NAME = "a saved step's file name must be one the folders store as an ordinary file";const NO_FOLLOW = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;function isInside(root: string, candidate: string): boolean {@@ -25,6 +27,9 @@ function writeInside(cwd: string, path: string, content: string): ExecResult {const target = resolvePath(root, path);const inside = relative(root, target);if (!inside || !isInside(root, target)) return { ok: false, error: FILE_OUTSIDE };+ // Containment alone is not enough: `NUL` opens a device and stores nothing, and `report.txt:notes` writes an NTFS+ // alternate stream that the person's own tools do not show - both inside the folder, both reported as written.+ for (const part of inside.split(sep)) if (unsafeFileNameProblem(part)) return { ok: false, error: FILE_NAME };const dir = dirname(target);// Check the deepest existing ancestor before creating folders so a symlinked directory cannot escape mkdirSync.for (let cur = dir; cur !== root;) {diff --git a/server/skill-folder.ts b/server/skill-folder.tsindex 6a8e96e657..10a4f360a6 100644--- a/server/skill-folder.ts+++ b/server/skill-folder.ts@@ -21,12 +21,18 @@ const unsafeCharacter = (char: string) => char < " " || char === "\u007f" || '<>const WINDOWS_DEVICE = /^(?:con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³])(?:\..*)?$/i;const SCRIPT = /\.(?:sh|bash|zsh|fish|ps1|psm1|bat|cmd|py|rb|pl|php|lua|js|mjs|cjs|ts)$/i;+/** Why one path segment may not name a file: characters a filesystem or Windows refuses, a trailing dot or space,+ * a Windows device name, or more than 255 bytes. Null when the segment may be used. */+export function unsafeFileNameProblem(part: string): "name" | null {+ return !part || part === "." || part === ".." || [...part].some(unsafeCharacter) || /[. ]$/.test(part) ||+ WINDOWS_DEVICE.test(part) || Buffer.byteLength(part, "utf8") > 255 ? "name" : null;+}+/** Why `path` (relative, "/"-separated) may not be written inside a skill folder; null when it may. */export function skillFilePathProblem(path: string, folder = false): SkippedSkillFileReason | null {const parts = path.split("/");for (const part of parts) {- if (!part || part === "." || part === ".." || [...part].some(unsafeCharacter) || /[. ]$/.test(part) ||- WINDOWS_DEVICE.test(part) || Buffer.byteLength(part, "utf8") > 255) return "name";+ if (unsafeFileNameProblem(part)) return "name";if (part.startsWith(".")) return "hidden";if (GENERATED.has(part.toLowerCase())) return "generated";}