Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(gateway): canonicalize public origin assignment

Abdurrahman Fakhrul145260a12981
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 179231a8..f246c089 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -13,6 +13,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `gateway` canonicalize public origin assignment
- `git` restore executable script modes
- `runtime` close service installer and notice races
- `install` hold update lock across checkout refresh
diff --git a/scripts/lib/gateway-config.sh b/scripts/lib/gateway-config.sh
index 3e40944e..b8a8929b 100644
--- a/scripts/lib/gateway-config.sh
+++ b/scripts/lib/gateway-config.sh
@@ -56,8 +56,8 @@ try { st = fs.fstatSync(fd); text = fs.readFileSync(fd, 'utf8'); } finally { fs.
if (!st.isFile() || st.uid !== process.getuid() || (st.mode & 0o077) !== 0) process.exit(2);
if (action === 'set') {
const line = `OS_PUBLIC_ORIGIN=${value}`;
- text = /^OS_PUBLIC_ORIGIN=.*$/m.test(text) ? text.replace(/^OS_PUBLIC_ORIGIN=.*$/m, line)
- : text + `${text.endsWith('\n') || !text ? '' : '\n'}${line}\n`;
+ text = text.replace(/^OS_PUBLIC_ORIGIN=.*\n?/gm, '');
+ text += `${text.endsWith('\n') || !text ? '' : '\n'}${line}\n`;
} else if (action === 'clear') text = text.replace(/^OS_PUBLIC_ORIGIN=.*\n?/gm, '');
else process.exit(2);
const tmp = `${file}.mso-gateway-${process.pid}`;
diff --git a/scripts/mso-gateway-origin.test.ts b/scripts/mso-gateway-origin.test.ts
new file mode 100644
index 00000000..c1ac58af
--- /dev/null
+++ b/scripts/mso-gateway-origin.test.ts
@@ -0,0 +1,27 @@
+import fs from "node:fs";
+import { describe, expect, it } from "vitest";
+import { fixture, readFileSnapshot, runGateway } from "./mso-gateway-test-fixture";
+
+describe("gateway public-origin canonicalization", () => {
+ it("replaces every previous OS_PUBLIC_ORIGIN assignment with exactly one requested value", () => {
+ const f = fixture();
+ fs.writeFileSync(
+ f.envFile,
+ [
+ "OS_SESSION_SECRET=fixture-only-not-a-real-secret",
+ "OS_PUBLIC_ORIGIN=https://old-first.example.test",
+ "KEEP_ME=1",
+ "OS_PUBLIC_ORIGIN=https://old-last.example.test",
+ "",
+ ].join("\n"),
+ );
+
+ runGateway(["domain", "set", "https://new.example.test"], f.baseEnv);
+ const snapshot = readFileSnapshot(f.envFile);
+ const origins = snapshot.text.match(/^OS_PUBLIC_ORIGIN=.*$/gm) ?? [];
+ expect(origins).toEqual(["OS_PUBLIC_ORIGIN=https://new.example.test"]);
+ expect(snapshot.text).toContain("OS_SESSION_SECRET=fixture-only-not-a-real-secret");
+ expect(snapshot.text).toContain("KEEP_ME=1");
+ expect(snapshot.mode).toBe(0o600);
+ });
+});