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.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
fix(browser): derive isolated Camoufox viewer origin
Rahman3de8e949ef0b
diff --git a/.env.example b/.env.exampleindex 70dfa0df..e0694f26 100644--- a/.env.example+++ b/.env.example@@ -171,9 +171,8 @@ OS_SESSION_SECRET=# process, cross-origin — so `window.top` is opaque:## 1. NEXT_PUBLIC_MANAGED_APP_HOST_TEMPLATE — `{id}` is the app id, so this-# yields hermes.mso.example.com, openclaw.mso.example.com, 9router.mso.example.com,-# and the reserved camoufox.mso.example.com viewer origin. Provision ONLY the-# explicit hosts you use; each needs its+# yields hermes.mso.example.com, openclaw.mso.example.com, and 9router.mso.example.com.+# Provision ONLY the explicit managed-app hosts you use; each needs its# own DNS record + TLS pointing at this app. On such a host the# middleware rewrites EVERY path into that app's proxy and 404s the rest, so# the cockpit API does not exist there.@@ -214,6 +213,18 @@ OS_SESSION_SECRET=# NEXT_PUBLIC_MANAGED_APP_HOST_TEMPLATE={id}.mso.example.com# OS_SESSION_COOKIE_DOMAIN=mso.example.com+# --- Camoufox viewer origin: separate auth, safe sibling by default ---+# The Browser viewer does not reuse the cockpit session cookie. An authenticated+# Operator/Owner receives a short-lived ticket, exchanged on the viewer origin for+# a host-only HttpOnly cookie before noVNC loads. With a namespace cookie such as+# mso.example.com, MSO derives camoufox.example.com automatically; with host-only+# login at mso.example.com it derives the same sibling. Provision DNS/TLS for the+# derived host, or override it with another HTTPS origin that is outside the current+# cockpit cookie Domain. Broad two-label cookie Domains intentionally require an+# explicit isolated origin because no safe sibling can be inferred.+# CAMOUFOX_VIEWER_ORIGIN=https://camoufox.example.com+# CAMOUFOX_NOVNC_URL=http://127.0.0.1:6080+# --- Storage paths (optional overrides) ---# OS_DEVICE_STORE=~/.mso/auth-devices.json # approved devices + live roles# OS_CONFIG_STORE=~/.mso/config.json # BYOK key + modeldiff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 4471409d..81ba797b 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -6,9 +6,16 @@ this is the *what*, and it is what Settings → About shows as “What's new”.## 2026-09-19+**Added**++- `mcp` encode agent bootstrap and capability-parity map+**Fixed**+- `browser` derive isolated Camoufox viewer origin- `browser` probe cache-isolated Camoufox path+- `mcp` keep architecture ratchet and bootstrap tests green+- `browser` route Camoufox websocket through viewer namespace- `browser` isolate Camoufox viewer cache## 2026-09-18diff --git a/docs/INSTALL.md b/docs/INSTALL.mdindex 10ca05c3..d53efaa2 100644--- a/docs/INSTALL.md+++ b/docs/INSTALL.md@@ -466,11 +466,16 @@ The service should be a systemd **user** unit named `camoufox-vnc.service`. It ito stay **disabled at boot**, with `Restart=no` and a finite runtime lease; the Browser UIpowers it on only when needed.-The noVNC document is never served on the cockpit origin. Configure-`NEXT_PUBLIC_MANAGED_APP_HOST_TEMPLATE` plus `OS_SESSION_COOKIE_DOMAIN`, provision the reserved-viewer host (for example `camoufox.mso.example.com`) with DNS/TLS, and keep-`CAMOUFOX_NOVNC_URL` loopback-only. The historical `/camoufox-vnc/*` route intentionally returns-404; the dedicated host strips cockpit cookies and authorization before forwarding to noVNC.+The noVNC document is never served on the cockpit origin and does not need the cockpit+Domain cookie. MSO gives an authenticated Operator/Owner a short-lived viewer ticket; the+separate viewer host exchanges it for a host-only HttpOnly cookie before noVNC loads. When+`OS_SESSION_COOKIE_DOMAIN=mso.example.com`, the safe default is `camoufox.example.com`; with a+host-only cockpit at `mso.example.com`, the same sibling is derived from `OS_PUBLIC_ORIGIN`.+Provision DNS/TLS for that host, or set `CAMOUFOX_VIEWER_ORIGIN` to another isolated HTTPS+origin. A broad two-label Domain cookie has no safely inferable sibling and therefore requires+an explicit isolated viewer origin. Keep `CAMOUFOX_NOVNC_URL` loopback-only. The historical+`/camoufox-vnc/*` route intentionally returns 404; the viewer gate never forwards cockpit+cookies or authorization to noVNC.Important paths/defaults:diff --git a/docs/PROGRESS.md b/docs/PROGRESS.mdindex 83f39162..7abade75 100644--- a/docs/PROGRESS.md+++ b/docs/PROGRESS.md@@ -1,3 +1,15 @@+## 2026-09-19 — Derive an isolated Camoufox sibling instead of assuming the managed-app namespace++Camoufox viewer authentication no longer needs the cockpit Domain cookie, so tying its hostname+to `{id}.mso.example.com` unnecessarily inherited deeper wildcard-certificate and cookie-scope+constraints. The viewer now prefers an explicit `CAMOUFOX_VIEWER_ORIGIN`, otherwise derives a+sibling outside the configured cookie namespace (`mso.example.com` → `camoufox.example.com`) or+from a host-only cockpit origin. Overrides that share the cockpit host/cookie Domain, contain+credentials, paths, queries, fragments or non-default ports fail closed. A broad two-label Domain+has no safely inferable sibling and requires an explicit separate viewer origin. Managed-app host+templates remain independent. A deployment shaped as `mso.operator.test` therefore resolves to+`camoufox.operator.test` without any maintainer-specific source literal.+## 2026-09-19 — Probe the cache-isolated Camoufox viewer entry pathThe viewer cache boundary moved noVNC under `/_mso-camoufox`, while the authenticateddiff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 9823472c..f9d7cab1 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -465,11 +465,15 @@ route; repeatedly starting an already running browser cannot fix it. Keep the vion its isolated origin, retain live Operator/Owner authorization, and never expose abare noVNC listener or disable certificate verification as a workaround.-A certificate for `*.example.com` does not cover `camoufox.mso.example.com`.-Check the edge provider's coverage independently from the origin certificate.-For Cloudflare full-setup Universal SSL, see its [hostname coverage limits](https://developers.cloudflare.com/ssl/edge-certificates/universal-ssl/limitations/).-DNS-only routing requires a publicly trusted origin certificate and the intended-origin route; changing the record also changes which edge protections apply.+A certificate for `*.example.com` covers `camoufox.example.com` but does not cover+`camoufox.mso.example.com`. MSO therefore derives the safe sibling outside a configured+`mso.example.com` cookie namespace when possible. If that hostname is not routed in your+deployment, set `CAMOUFOX_VIEWER_ORIGIN` to an isolated HTTPS origin with valid DNS/TLS; do+not move it back inside the cockpit cookie Domain. Check edge coverage independently from+the origin certificate. For Cloudflare full-setup Universal SSL, see its+[hostname coverage limits](https://developers.cloudflare.com/ssl/edge-certificates/universal-ssl/limitations/).+DNS-only routing requires a publicly trusted origin certificate and the intended origin route;+changing the record also changes which edge protections apply.The browser session may stop at its configured service time limit. A failed transportprobe is not a stopped process. Verify actual navigation independently using an isolateddiff --git a/lib/camoufox/origin.test.ts b/lib/camoufox/origin.test.tsindex 718ac63b..63f7060b 100644--- a/lib/camoufox/origin.test.ts+++ b/lib/camoufox/origin.test.ts@@ -3,58 +3,92 @@ import { afterEach, describe, expect, it, vi } from "vitest";afterEach(() => vi.unstubAllEnvs());async function load(- template: string,+ template = "{id}.mso.example.com",publicOrigin = "https://mso.example.com",viewerOrigin = "",+ cookieDomain = "mso.example.com",) {vi.resetModules();vi.stubEnv("NEXT_PUBLIC_MANAGED_APP_HOST_TEMPLATE", template);vi.stubEnv("OS_PUBLIC_ORIGIN", publicOrigin);vi.stubEnv("CAMOUFOX_VIEWER_ORIGIN", viewerOrigin);+ vi.stubEnv("OS_SESSION_COOKIE_DOMAIN", cookieDomain);return import("./origin");}describe("Camoufox split origin", () => {- it("reserves one host in the managed-app namespace", async () => {- const mod = await load("{id}.mso.example.com");- expect(mod.camoufoxViewerHost()).toBe("camoufox.mso.example.com");- expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.mso.example.com");- expect(mod.isCamoufoxViewerHost("camoufox.mso.example.com:443")).toBe(true);+ it("derives a sibling outside the managed-app cookie namespace by default", async () => {+ const mod = await load();+ expect(mod.camoufoxViewerHost()).toBe("camoufox.example.com");+ expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.example.com");+ expect(mod.isCamoufoxViewerHost("camoufox.example.com:443")).toBe(true);+ expect(mod.isCamoufoxViewerHost("camoufox.mso.example.com")).toBe(false);});- it("has no same-origin fallback when the namespace is disabled", async () => {- const mod = await load("");- expect(mod.camoufoxViewerOrigin()).toBeNull();- expect(mod.isCamoufoxViewerHost("mso.example.com")).toBe(false);+ it("derives the deployment sibling for an arbitrary three-label cookie namespace", async () => {+ const mod = await load(+ "{id}.mso.operator.test",+ "https://mso.operator.test",+ "",+ "mso.operator.test",+ );+ expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.operator.test");});-- it("can use an explicit sibling viewer origin without changing the managed-app namespace", async () => {+ it("uses an explicit isolated viewer origin without changing the managed-app namespace", async () => {const mod = await load("{id}.mso.example.com","https://mso.example.com",- "https://camoufox-mso.example.com",+ "https://browser.example.net",);- expect(mod.camoufoxViewerHost()).toBe("camoufox-mso.example.com");- expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox-mso.example.com");- expect(mod.isCamoufoxViewerHost("camoufox-mso.example.com:443")).toBe(true);- expect(mod.isCamoufoxViewerHost("camoufox.mso.example.com")).toBe(false);+ expect(mod.camoufoxViewerHost()).toBe("browser.example.net");+ expect(mod.camoufoxViewerOrigin()).toBe("https://browser.example.net");+ expect(mod.isCamoufoxViewerHost("browser.example.net:443")).toBe(true);+ });++ it("refuses explicit viewer origins that can receive the cockpit Domain cookie", async () => {+ for (const value of [+ "https://camoufox.mso.example.com",+ "https://mso.example.com",+ ]) {+ const mod = await load("{id}.mso.example.com", "https://mso.example.com", value);+ expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.example.com");+ vi.unstubAllEnvs();+ }});- it("rejects unsafe viewer-origin overrides and keeps the safe namespace fallback", async () => {+ it("rejects malformed overrides and falls back to the safe derived sibling", async () => {for (const value of [- "http://camoufox-mso.example.com",- "https://user:[email protected]",- "https://camoufox-mso.example.com/path",+ "http://camoufox.example.com",+ "https://user:[email protected]",+ "https://camoufox.example.com:8443",+ "https://camoufox.example.com/path",]) {const mod = await load("{id}.mso.example.com", "https://mso.example.com", value);- expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.mso.example.com");+ expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.example.com");vi.unstubAllEnvs();}});+ it("fails closed when a broad two-label Domain cookie leaves no safe automatic sibling", async () => {+ const mod = await load(+ "{id}.mso.example.com",+ "https://mso.example.com",+ "",+ "example.com",+ );+ expect(mod.camoufoxViewerOrigin()).toBeNull();+ expect(mod.isCamoufoxViewerHost("camoufox.mso.example.com")).toBe(false);+ });++ it("can derive a sibling with host-only sessions even when managed-app embedding is disabled", async () => {+ const mod = await load("", "https://mso.example.com", "", "");+ expect(mod.camoufoxViewerOrigin()).toBe("https://camoufox.example.com");+ expect(mod.isCamoufoxViewerHost("mso.example.com")).toBe(false);+ });+it("allows only the cockpit to frame the viewer and no outbound forms", async () => {- const mod = await load("{id}.mso.example.com");+ const mod = await load();const csp = mod.camoufoxViewerCsp();expect(csp).toContain("frame-ancestors https://mso.example.com");expect(csp).toContain("form-action 'none'");diff --git a/lib/camoufox/origin.ts b/lib/camoufox/origin.tsindex c01aa7b8..c1d92832 100644--- a/lib/camoufox/origin.ts+++ b/lib/camoufox/origin.ts@@ -1,10 +1,35 @@// noVNC is third-party code with keyboard/mouse access to a logged-in browser. It// must never share the cockpit origin: on its own host, window.top and every MSO API// are cross-origin, while middleware maps every path only to loopback noVNC.+import { configuredSessionCookieScope } from "@/lib/auth/session-cookie";import { appNamespaceHost, cockpitOrigin } from "@/lib/managed-apps/origin";export const CAMOUFOX_VIEWER_LABEL = "camoufox";+const normalizeHost = (value: string) => value.replace(/\.$/, "").toLowerCase();+const domainMatches = (host: string, domain: string) =>+ host === domain || host.endsWith(`.${domain}`);++function currentCookieDomain(): string | null {+ const scope = configuredSessionCookieScope();+ return scope.startsWith("domain:") ? scope.slice("domain:".length) : null;+}++function cockpitHost(): string | null {+ const origin = cockpitOrigin();+ if (!origin) return null;+ try { return normalizeHost(new URL(origin).hostname); }+ catch { return null; }+}++function viewerHostIsIsolated(host: string): boolean {+ host = normalizeHost(host);+ const cockpit = cockpitHost();+ if (cockpit && host === cockpit) return false;+ const cookieDomain = currentCookieDomain();+ return !cookieDomain || !domainMatches(host, cookieDomain);+}+function configuredViewerOrigin(): URL | null {const raw = process.env.CAMOUFOX_VIEWER_ORIGIN?.trim();if (!raw) return null;@@ -14,9 +39,11 @@ function configuredViewerOrigin(): URL | null {url.protocol !== "https:" ||url.username ||url.password ||+ url.port ||url.pathname !== "/" ||url.search ||- url.hash+ url.hash ||+ !viewerHostIsIsolated(url.hostname)) return null;return url;} catch {@@ -24,21 +51,49 @@ function configuredViewerOrigin(): URL | null {}}+function derivedSiblingHost(): string | null {+ // Managed-app deployments commonly widen the cockpit cookie only to a namespace+ // such as mso.example.com. Place Camoufox beside that namespace so the browser+ // cannot send the cockpit cookie to the viewer at all.+ const cookieDomain = currentCookieDomain();+ if (cookieDomain) {+ const labels = cookieDomain.split(".");+ if (labels.length < 3) return null;+ const candidate = `${CAMOUFOX_VIEWER_LABEL}.${labels.slice(1).join(".")}`;+ return viewerHostIsIsolated(candidate) ? candidate : null;+ }++ // Host-only cockpit cookies are already isolated by hostname. Prefer a sibling+ // of the cockpit host when one can be derived without guessing a public suffix.+ const cockpit = cockpitHost();+ if (cockpit) {+ const labels = cockpit.split(".");+ if (labels.length >= 3) {+ const candidate = `${CAMOUFOX_VIEWER_LABEL}.${labels.slice(1).join(".")}`;+ if (viewerHostIsIsolated(candidate)) return candidate;+ }+ }++ // Legacy host-template fallback remains safe only for host-only sessions.+ const namespaced = appNamespaceHost(CAMOUFOX_VIEWER_LABEL);+ return namespaced && viewerHostIsIsolated(namespaced) ? namespaced : null;+}+export function camoufoxViewerHost(): string | null {- return configuredViewerOrigin()?.host.toLowerCase() ?? appNamespaceHost(CAMOUFOX_VIEWER_LABEL);+ return configuredViewerOrigin()?.hostname.toLowerCase() ?? derivedSiblingHost();}export function camoufoxViewerOrigin(): string | null {const configured = configuredViewerOrigin();if (configured) return configured.origin;- const host = camoufoxViewerHost();- return host ? "https://" + host : null;+ const host = derivedSiblingHost();+ return host ? `https://${host}` : null;}export function isCamoufoxViewerHost(host: string | null | undefined): boolean {const expected = camoufoxViewerHost();if (!host || !expected) return false;- return host.split(":")[0].replace(/\.$/, "").toLowerCase() === expected;+ return normalizeHost(host.split(":")[0]) === expected;}export function camoufoxViewerCsp(): string {diff --git a/lib/camoufox/viewer-gate.test.ts b/lib/camoufox/viewer-gate.test.tsindex 82a6aa38..5c9086da 100644--- a/lib/camoufox/viewer-gate.test.ts+++ b/lib/camoufox/viewer-gate.test.ts@@ -63,6 +63,7 @@ describe("the Camoufox split-origin VNC bridge", () => {async function load(novnc = NOVNC) {vi.stubEnv("OS_SESSION_SECRET", SECRET);vi.stubEnv("OS_PUBLIC_ORIGIN", "https://mso.example.com");+ vi.stubEnv("OS_SESSION_COOKIE_DOMAIN", "mso.example.com");vi.stubEnv("CAMOUFOX_NOVNC_URL", novnc);vi.stubEnv("CAMOUFOX_VIEWER_ORIGIN", "https://" + VIEWER_HOST);approved.value = true;