Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(safety): skip every env operand holding =, as GNU env sets them all
DheerajPiduru524d501e86eaa8
diff --git a/server/safety-floor.test.ts b/server/safety-floor.test.tsindex e7e7fde94d..f3ea693536 100644--- a/server/safety-floor.test.ts+++ b/server/safety-floor.test.ts@@ -112,6 +112,8 @@ const BLOCKED: Case[] = [["env - rm -rf /", "delete-root"],["env -i - PATH=/bin rm -rf /etc", "delete-system-directory"],["sudo env - rm -rf ~", "delete-home"],+ ["env - 'X-Y=1' rm -rf /etc", "delete-system-directory"],+ ["env 'X-Y=1' rm -rf /etc", "delete-system-directory"],// `env -S LINE` / `--split-string=LINE`: env runs what it splits LINE into["env -S 'rm -rf /'", "delete-root"],['env -S"rm -rf /"', "delete-root"],@@ -379,6 +381,7 @@ const ALLOWED: Array<[command: string, on?: Platform | "posix"]> = [["env -S 'echo rm -rf /'"],["env -S 'node --no-warnings' script.js"],["env - PATH=/bin ls -la /"],+ ["env 'X-Y=1' ls -la /"],// env hands rm a directory named "~": nothing expands it without a shell["env -S 'rm -rf ~'"],["printf '%s\\n' 'rm -rf /' > notes.txt"],diff --git a/server/safety-floor.ts b/server/safety-floor.tsindex 3626f06e9e..44b28609c8 100644--- a/server/safety-floor.ts+++ b/server/safety-floor.ts@@ -339,12 +339,12 @@ function lex(source: string, windows: boolean): Reading {/** Commands that run the command after them. `values`/`named`: options taking a value; `asks`: options that only* report on the command; `split`: the option whose value is more arguments (`env -S`); `loneDash`: a `-` after the- * options is one more option (env's `-` is `-i`). */-const PREFIXES: Record<string, { values?: string; named?: string[]; operands?: number; asks?: string; asksNamed?: string[]; split?: { letter: string; named: string }; loneDash?: boolean }> = {+ * options is one more option (env's `-` is `-i`); `assigns`: every operand holding `=` is set, whatever its name. */+const PREFIXES: Record<string, { values?: string; named?: string[]; operands?: number; asks?: string; asksNamed?: string[]; split?: { letter: string; named: string }; loneDash?: boolean; assigns?: boolean }> = {// `sudo -l rm` lists whether rm may be run; it runs nothing.sudo: { values: "CDghpRrtTUu", named: ["user", "group", "host", "prompt", "chdir", "chroot", "role", "type", "other-user", "close-from", "command-timeout"], asks: "l", asksNamed: ["list"] },doas: { values: "Cu" },- env: { values: "uCS", named: ["unset", "chdir", "split-string"], split: { letter: "S", named: "split-string" }, loneDash: true },+ env: { values: "uCS", named: ["unset", "chdir", "split-string"], split: { letter: "S", named: "split-string" }, loneDash: true, assigns: true },nice: { values: "n", named: ["adjustment"] },timeout: { values: "ks", named: ["kill-after", "signal"], operands: 1 },exec: { values: "a" },@@ -445,6 +445,7 @@ function commandIndex(words: string[], unread: () => void): number {words.splice(--index, spliced, ...parts);}if (prefix.loneDash && words[index] === "-") index++;+ if (prefix.assigns) while (index < words.length && words[index].includes("=")) index++;index += prefix.operands ?? 0;}return -1;