Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(safety): read %HOMEDRIVE%%HOMEPATH% as the home directory, like %USERPROFILE%

Dheeraj Pidurubfc4c09a4d8e
diff --git a/server/safety-floor.test.ts b/server/safety-floor.test.ts
index 50f04efd5e..5d14b1b558 100644
--- a/server/safety-floor.test.ts
+++ b/server/safety-floor.test.ts
@@ -180,6 +180,9 @@ const BLOCKED: Case[] = [
['rd /s /q "C:\\"', "delete-root", "win32"],
["rd /s /q %USERPROFILE%", "delete-home", "win32"],
['rmdir /s /q "%USERPROFILE%"', "delete-home", "win32"],
+ ["rd /s /q %HOMEDRIVE%%HOMEPATH%", "delete-home", "win32"],
+ ['rmdir /s /q "%homedrive%%homepath%"', "delete-home", "win32"],
+ ["cmd /c rd /s/q %HOMEDRIVE%%HOMEPATH%\\", "delete-home", "win32"],
["rd /s /q C:\\Windows", "delete-system-directory", "win32"],
["rmdir /S /Q C:\\Users", "delete-system-directory", "win32"],
['rd /s /q "C:\\Program Files"', "delete-system-directory", "win32"],
@@ -459,6 +462,7 @@ const ALLOWED: Array<[command: string, on?: Platform | "posix"]> = [
["rd /s /q C:\\Users\\omkar\\project\\node_modules"],
["rd /s /q %TEMP%\\scratch"],
["rd /s /q %USERPROFILE%\\Downloads\\old"],
+ ["rd /s /q %HOMEDRIVE%%HOMEPATH%\\Downloads\\old"],
["rd C:\\Windows"],
["del /s /q *.tmp"],
["del /s /q C:\\Temp\\*"],
diff --git a/server/safety-floor.ts b/server/safety-floor.ts
index 493fc49692..f7e45fe277 100644
--- a/server/safety-floor.ts
+++ b/server/safety-floor.ts
@@ -532,7 +532,11 @@ function posixTarget(word: string, host: Host): FloorVerdict | null {
/** posixTarget for a cmd or PowerShell path. `percent`: a cmd command, where `%NAME%` expands anywhere. */
function windowsTarget(word: string, percent: boolean, host: Host): FloorVerdict | null {
- const expanded = percent ? word.replace(/%([^%\s]+)%/g, (_match, name: string) => WINDOWS_VARIABLES[name.toLowerCase()] ?? DYNAMIC) : word;
+ // Windows spells the home directory %HOMEDRIVE%%HOMEPATH% as well as %USERPROFILE%.
+ const expanded = percent
+ ? word.replace(/%homedrive%%homepath%/gi, "%USERPROFILE%")
+ .replace(/%([^%\s]+)%/g, (_match, name: string) => WINDOWS_VARIABLES[name.toLowerCase()] ?? DYNAMIC)
+ : word;
if (expanded.includes(DYNAMIC)) return null;
const fromHome = expanded.startsWith(HOME);
const path = (fromHome ? expanded.slice(1) : expanded).replace(/\//g, "\\");