Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
});