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: persist the ready tunnel process identity after launcher exec

Rahman9b83b6f848b7
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index ef3f9874..20175156 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -10,6 +10,10 @@ The release build is followed by synthetic browser journeys for desktop, phone p
Public GitHub CI passed, but separate security gates identified a legacy E2E credential flow, a missing explicit GCM tag-length option, and historical scanner false positives. Native desktop and Preview scripts now run a built app with disposable credentials/stores and explicitly seeded live test preferences; they never read deployment passwords or approved production devices. Authentication refuses redirects. AES-GCM encryption/decryption explicitly require 16-byte tags, with a regression test rejecting truncated tags before import. The history allowlist adds only reviewed commit/path/line fingerprints for synthetic Dokploy keys and DOM maxLength/hidden assignments; no broad rule/path exclusion or history rewrite is used. Chained form assignments are split to avoid new false positives. Local pinned Semgrep reports zero findings (38 existing parser warnings); pinned Gitleaks scans 541 commits with no unignored findings. The seven transfer tests pass. The extended out-of-tree production build also passes required release journeys, native Windows/macOS Files and Settings interactions, and Preview byte-loading/sandbox checks for image, PDF, audio/video, Markdown, CSV, HTML and text; no unexpected HTTP or browser-console errors remain.
+### Gateway startup identity race
+
+GitHub's concurrent-start test exposed a real startup race: a script launcher can exec an interpreter with the same PID/start ticks after MSO captures its initial executable/argv identity. Persisting that stale identity let a second start treat the live tunnel as absent and create another. After public readiness, MSO now revalidates the exact command and owned process lifetime, captures the final identity, and only then commits state. A delayed interpreter-exec fixture reproduced two live tunnels before the fix; both direct and interpreter starts now require exactly one spawned/live tunnel whose full identity matches the saved state. Login return paths additionally reject paths that normalize into scheme-relative external destinations, including encoded dot segments.
+
## 2026-09-09 — Instance portability and MCP privacy boundary
MSO source no longer owns an operator hostname, home path, project root, MCP widget origin, or external Page app. Browser origin comes from `OS_PUBLIC_ORIGIN`; the MCP Apps sibling origin is derived per installation or overridden with `OS_MCP_UI_ORIGIN`; reviewed external Page apps are an empty-by-default, bounded `MSO_SURFACE_APPS_JSON` catalog. Current repository/worktree instructions resolve the active checkout rather than assuming a maintainer home. A repository-wide instance-literal gate now rejects known operator-instance domains/paths across runtime code, tests, docs, workflows, and official skills. Maintainer deployments keep their own public values only in ignored/local runtime configuration.
diff --git a/scripts/lib/gateway-tunnel.sh b/scripts/lib/gateway-tunnel.sh
index dc89547b..5dac8161 100644
--- a/scripts/lib/gateway-tunnel.sh
+++ b/scripts/lib/gateway-tunnel.sh
@@ -82,6 +82,20 @@ gateway_spawn_tunnel() {
GATEWAY_PENDING_CLEANUP=1
}
+# A script launcher can exec its interpreter without changing PID/start ticks.
+# After readiness, persist the final executable/argv identity, not its startup wrapper.
+gateway_refresh_tunnel_identity() {
+ local pid="$TUNNEL_PENDING_PID" identity
+ if [ "$GATEWAY_MODE" = temporary ]; then
+ identity="$(gateway_wait_spawn_identity "$pid" "$CLOUDFLARED" tunnel --no-autoupdate --url "$LOCAL_URL" 2>/dev/null || true)"
+ else
+ identity="$(gateway_wait_spawn_identity "$pid" "$CLOUDFLARED" tunnel --config "$GATEWAY_CONFIG" --no-autoupdate run "$GATEWAY_TUNNEL" 2>/dev/null || true)"
+ fi
+ [ -n "$identity" ] && [ "$(jq -r .startTicks <<<"$identity")" = "$TUNNEL_PENDING_TICKS" ] \
+ && gateway_identity_matches "$identity" || return 1
+ TUNNEL_IDENTITY="$identity"
+}
+
gateway_discover_quick_url() {
local pid i
pid="$(jq -r .pid <<<"$TUNNEL_IDENTITY")"
@@ -187,6 +201,7 @@ gateway_cmd_start_locked() {
GATEWAY_PUBLIC_URL="$(gateway_validate_public_origin "$GATEWAY_PUBLIC_URL" 2>/dev/null || true)"
[ -n "$GATEWAY_PUBLIC_URL" ] || { gateway_cleanup_failed_start; gateway_fail "tunnel produced an invalid public origin"; }
gateway_probe_public || { gateway_cleanup_failed_start; gateway_fail "public endpoint did not return the MSO health contract; see $CF_LOG"; }
+ gateway_refresh_tunnel_identity || { gateway_cleanup_failed_start; gateway_fail "ready tunnel no longer matches its spawned process"; }
if ! gateway_write_state "$GATEWAY_PROVIDER" "$GATEWAY_MODE" "$GATEWAY_PUBLIC_URL" "$TUNNEL_IDENTITY"; then
gateway_cleanup_failed_start
gateway_fail "could not persist gateway state; newly launched processes were rolled back"
diff --git a/scripts/mso-gateway-lifecycle.test.ts b/scripts/mso-gateway-lifecycle.test.ts
index 91b5808c..1af0e447 100644
--- a/scripts/mso-gateway-lifecycle.test.ts
+++ b/scripts/mso-gateway-lifecycle.test.ts
@@ -228,17 +228,26 @@ exec /bin/mv "$@"
expect(readRegularSnapshot(markerPath).text.trim()).toBe("1");
});
- it("serializes concurrent starts so only one tunnel remains live and tracked", async () => {
+ it.each(["direct", "interpreter exec"])("serializes concurrent starts so only one tunnel remains live and tracked (%s)", async mode => {
const f = fixture(), startFile = f.startFile, env = f.env;
+ if (mode === "interpreter exec") {
+ fs.renameSync(f.cloudflared, f.cloudflared + ".cjs");
+ // Preserve PID/start ticks while startup changes executable and argv.
+ fs.writeFileSync(f.cloudflared, `#!/bin/bash
+sleep 0.3
+exec node -e 'require(process.argv[1] + ".cjs")' "$0" "$@"
+`, { mode: 0o700 });
+ }
const [a, b] = await Promise.all([asyncStart(env), asyncStart(env)]);
expect(a.code).toBe(0); expect(b.code).toBe(0);
const spawned = fs.readFileSync(startFile, "utf8").trim().split(/\n+/).filter(Boolean).map(Number);
- expect(spawned.length).toBeGreaterThan(0);
for (const pid of spawned) pids.add(pid);
+ expect(spawned).toHaveLength(1);
const live = spawned.filter(alive);
expect(live).toHaveLength(1);
const state = JSON.parse(fs.readFileSync(path.join(f.state, "state.json"), "utf8"));
expect(state.tunnelIdentity.pid).toBe(live[0]);
+ expect(state.tunnelIdentity).toMatchObject(identity(live[0]));
run(["stop"], f.env);
for (let i = 0; i < 50 && spawned.some(alive); i++) await new Promise((r) => setTimeout(r, 20));
expect(spawned.filter(alive)).toEqual([]);