Skip to content

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

static files: refuse a served path that resolves to another drive

milind-soni99f817329660
diff --git a/server/static-files.ts b/server/static-files.ts
index cf49a57c7b..9dff8f93e7 100644
--- a/server/static-files.ts
+++ b/server/static-files.ts
@@ -1,7 +1,7 @@
// The desktop bundle served from OMB_STATIC_DIR: content types, cache rules and the SPA fallback.
import { readFileSync, statSync } from "node:fs";
import type { IncomingMessage, ServerResponse } from "node:http";
-import { extname, join, relative, resolve } from "node:path";
+import { extname, isAbsolute, join, relative, resolve } from "node:path";
const MIME: Record<string, string> = {
".html": "text/html",
@@ -79,7 +79,8 @@ function resolveInside(root: string, target: string): string | null {
const base = resolve(root);
const full = resolve(base, target.replace(/^\/+/, ""));
const rel = relative(base, full);
- if (rel.startsWith("..") || rel.includes("\0")) return null;
+ // isAbsolute: on Windows a path naming another drive ("/D:/x") resolves outside, and relative() returns it whole.
+ if (rel.startsWith("..") || isAbsolute(rel) || rel.includes("\0")) return null;
return full;
}