From 409fab72b70527a0e99b9af820cb35a5b8a2c184 Mon Sep 17 00:00:00 2001 From: Ayman Mohamed Elsaid Ali Date: Thu, 19 Nov 2026 21:02:28 +0100 Subject: [PATCH] fix(server): trim whitespace and drop empty entries in ALLOWED_ORIGINS --- apps/server/src/config.ts | 7 ++++--- tests/config.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/server/src/config.ts b/apps/server/src/config.ts index 34084326b..ec5239a52 100644 --- a/apps/server/src/config.ts +++ b/apps/server/src/config.ts @@ -181,9 +181,10 @@ export function readConfig(): Config { computerProvider, computerE2bTemplate: process.env.COMPUTER_E2B_TEMPLATE?.trim() || "desktop", e2bApiKey, - allowedOrigins: ( - process.env.ALLOWED_ORIGINS ?? "http://localhost:8081,http://127.0.0.1:8081" - ).split(","), + allowedOrigins: (process.env.ALLOWED_ORIGINS ?? "http://localhost:8081,http://127.0.0.1:8081") + .split(",") + .map((origin) => origin.trim()) + .filter(Boolean), // Only trust X-Forwarded-For/X-Real-IP when the deployment is known to sit // behind a proxy that sets them; otherwise a direct caller can spoof them. trustProxy: process.env.TRUST_PROXY === "true", diff --git a/tests/config.test.ts b/tests/config.test.ts index 7d9943b22..8b5df1bfe 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -177,3 +177,21 @@ test("installs from before the rename keep their access key and data directory", await mkdir(join(root, ".openfuse")); assert.equal(defaultDataDir(root), ".openfuse"); }); + +test("ALLOWED_ORIGINS entries are trimmed and empty entries are ignored", (t) => { + const previous = { ...process.env }; + t.after(() => { + process.env = previous; + }); + process.env.WORKSPACE_MODE = "sample"; + process.env.AGENT_BACKEND = "sample"; + process.env.HOST = "127.0.0.1"; + process.env.CPK_INTELLIGENCE_API_KEY = "test-project-key-never-sent"; + process.env.ALLOWED_ORIGINS = " https://app.example.com , https://admin.example.com , , "; + assert.deepEqual(readConfig().allowedOrigins, [ + "https://app.example.com", + "https://admin.example.com", + ]); + process.env.ALLOWED_ORIGINS = " "; + assert.deepEqual(readConfig().allowedOrigins, []); +});