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(gateway): harden update and proxy edges
Rahman33d4ea8f347b
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 1dcecc59..488b3ce5 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` harden update and proxy edges- `gateway` close lifecycle review gaps- `security` harden gateway scanner fixtures- `install` survive Bun bin metadata corruptiondiff --git a/docs/INSTALL.md b/docs/INSTALL.mdindex 5ac704b1..9c429de4 100644--- a/docs/INSTALL.md+++ b/docs/INSTALL.md@@ -429,7 +429,9 @@ mso update log```The updater verifies the incoming checkout/build before replacing the service. With an active-`mso.service` it runs outside that service cgroup so the updater survives the restart. With no active+`mso.service` it first canonicalizes the unit's `WorkingDirectory` and requires it to equal the checkout+that invoked `mso update`; a secondary clone is never allowed to restart an unrelated live service.+The updater then runs outside that service cgroup so it survives the restart. With no activeservice (including WSL without systemd), it performs the clean fast-forward/dependency/verify/buildpath locally. If `mso web`/gateway owns the detached Next runtime, update first quiesces only thatverified runtime, leaves an active tunnel identity intact, rebuilds, then restores the runtime. Adiff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex c3e1a8b5..5da47c45 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -39,6 +39,12 @@ failures, so rerunning the same `mso update` retries dependency/build/restart woalready equals `origin/main`. Use `mso update status` for source/deployment state and `mso update log`for the service-updater transcript.+### `mso update` says the active service belongs to another checkout++This is a safety refusal. A machine may contain multiple MSO clones, but an active `mso.service` has+one canonical `WorkingDirectory`. Run the update from that checkout (normally the directory targeted+by the installer) instead of letting a secondary clone rebuild itself and restart someone else's unit.+### `mso gateway start` cannot install or verify cloudflaredCurrent MSO installs a reviewed `cloudflared` release automatically into `~/.mso/tools` on first@@ -54,6 +60,13 @@ contract; this is readiness tolerance, not a weaker health check. A local resolvinitial NXDOMAIN longer than the record creation itself; temporary mode therefore has a CloudflareDoH fallback that still verifies HTTPS for the generated hostname and the exact runtime nonce.+### `mso gateway` misdetects local health when my shell uses an HTTP proxy++Current MSO explicitly bypasses configured HTTP/HTTPS proxies for the already-validated loopback+`/api/health` probe. Public HTTPS readiness still follows normal proxy policy. If `mso gateway doctor`+still cannot verify the local runtime, inspect the local bind/build rather than adding the public+Quick Tunnel hostname to `NO_PROXY`.+### Temporary gateway opens, but Terminal does not streamCloudflare Quick Tunnels are the no-custom-domain preview mode and do not support Server-Sentdiff --git a/scripts/lib/gateway-common.sh b/scripts/lib/gateway-common.shindex 94dffdb1..2bde57fd 100644--- a/scripts/lib/gateway-common.sh+++ b/scripts/lib/gateway-common.sh@@ -162,8 +162,13 @@ gateway_health_body_ok() {}gateway_health_url_ok() {- local base="$1" expected_instance="${2-}" body- body="$("$CURL" -fsS --max-time 4 "$base/api/health" 2>/dev/null || true)"+ local base="$1" expected_instance="${2-}" body loopback+ local -a curl_args=(-fsS --max-time 4)+ loopback="$(gateway_validate_loopback_origin "$base" 2>/dev/null || true)"+ # A user's http_proxy/HTTP_PROXY must never redirect the trusted local-health+ # decision through a proxy. Public HTTPS probes retain ordinary proxy behavior.+ [ -z "$loopback" ] || curl_args+=(--noproxy '*')+ body="$("$CURL" "${curl_args[@]}" "$base/api/health" 2>/dev/null || true)"gateway_health_body_ok "$body" "$expected_instance"}diff --git a/scripts/mso-gateway.test.ts b/scripts/mso-gateway.test.tsindex ec1a569e..b002aa78 100644--- a/scripts/mso-gateway.test.ts+++ b/scripts/mso-gateway.test.ts@@ -77,6 +77,23 @@ esacexpect(out.stderr).toContain("non-loopback listener");});++ it("bypasses configured HTTP proxies for the trusted loopback health probe", () => {+ const f = fixture();+ const capture = path.join(f.dir, "curl-argv");+ fs.writeFileSync(f.curl, `#!/bin/sh+printf '%s\n' "$@" > "${capture}"+printf '%s\n' '{"status":"ok","buildId":"fixture","runtimeInstanceId":"fixture","version":"${VERSION}"}'+`, { mode: 0o700 });+ const out = run(["doctor"], { ...f.baseEnv, HTTP_PROXY: "http://proxy.invalid:8080", http_proxy: "http://proxy.invalid:8080", NO_PROXY: "", no_proxy: "" });+ expect(out).toContain("verified MSO runtime");+ const argv = fs.readFileSync(capture, "utf8").trim().split(/\n/);+ const noproxy = argv.indexOf("--noproxy");+ expect(noproxy).toBeGreaterThanOrEqual(0);+ expect(argv[noproxy + 1]).toBe("*");+ expect(argv.at(-1)).toBe("http://127.0.0.1:4005/api/health");+ });+it("fails closed on a non-loopback upstream", () => {const f = fixture();const out = spawnSync(GATEWAY, ["start"], {diff --git a/scripts/mso-update b/scripts/mso-updateindex d79c2869..865e5811 100755--- a/scripts/mso-update+++ b/scripts/mso-update@@ -28,6 +28,20 @@ require_checkout() {fetch_main() { git -C "$ROOT" fetch --quiet origin main || fail "could not reach origin/main"; }+service_is_active() { command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet mso.service; }++require_service_checkout() {+ local configured canonical_root canonical_service+ configured="$(systemctl show -p WorkingDirectory --value mso.service 2>/dev/null || true)"+ [ -n "$configured" ] || fail "active mso.service has no readable WorkingDirectory; refusing update handoff"+ canonical_root="$(realpath -e -- "$ROOT" 2>/dev/null || true)"+ canonical_service="$(realpath -e -- "$configured" 2>/dev/null || true)"+ [ -n "$canonical_root" ] && [ -n "$canonical_service" ] \+ || fail "cannot canonicalize active mso.service WorkingDirectory; refusing update handoff"+ [ "$canonical_service" = "$canonical_root" ] \+ || fail "active mso.service belongs to $canonical_service, not this checkout $canonical_root; run update from the service checkout"+}+init_update_state() {[ -n "$UPDATE_STATE_DIR" ] && return 0UPDATE_STATE_DIR="$(mso_private_state_dir "$UPDATE_STATE_DIR_REQUESTED")" || fail "unsafe update state directory"@@ -83,10 +97,12 @@ print_status() {printf 'run: mso update\n'returnfi- if command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet mso.service; then+ if service_is_active; then+ require_service_checkoutprintf 'mso %s is up to date (%s)\n' "${local_v:-unknown}" "${head:0:7}"returnfi+ init_update_stateif [ -e "$DEPLOY_RECEIPT" ] || [ -L "$DEPLOY_RECEIPT" ]; then receipt="$(read_receipt)"; fiif [ "$receipt" != "$head" ] || restart_pending; thenprintf 'source is current at %s, but offline deployment verification/restart is pending. run: mso update\n' "${head:0:7}"@@ -142,7 +158,8 @@ run_update() {local rebuild_only="$1" arg=""require_checkout[ "$rebuild_only" != 1 ] || arg="--rebuild-only"- if command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet mso.service; then+ if service_is_active; then+ require_service_checkoutif command -v systemd-run >/dev/null 2>&1 && systemctl --user show-environment >/dev/null 2>&1; thenmkdir -p "$(dirname "$LOG")"; chmod 700 "$(dirname "$LOG")" 2>/dev/null || truesystemd-run --user --collect --unit=mso-self-update --property=TimeoutStartSec=3600 \diff --git a/scripts/mso-update.test.ts b/scripts/mso-update.test.tsindex d7bd06d7..fcc18b00 100644--- a/scripts/mso-update.test.ts+++ b/scripts/mso-update.test.ts@@ -9,7 +9,7 @@ const PRIVATE = path.join(process.cwd(), "scripts/lib/private-state.sh");const roots: string[] = [];function git(cwd: string, ...args: string[]) { return execFileSync("git", args, { cwd, encoding: "utf8" }).trim(); }-function fixture(options: { failInstallOnce?: boolean } = {}) {+function fixture(options: { failInstallOnce?: boolean; activeService?: "same" | "other" } = {}) {const root = fs.mkdtempSync(path.join(os.tmpdir(), "mso-update-")); roots.push(root);const repo = path.join(root, "repo"), remote = path.join(root, "remote.git"), bin = path.join(root, "bin"), capture = path.join(root, "capture");fs.mkdirSync(path.join(repo, "scripts/lib"), { recursive: true }); fs.mkdirSync(path.join(repo, "bin")); fs.mkdirSync(bin);@@ -28,7 +28,14 @@ case "$1" in runtime-stop) echo 'runtime: stopped-owned' ;; local-start) echo 'rfs.writeFileSync(path.join(repo, "bin/mso"), '#!/bin/sh\nVERSION="1.4.0"\n', { mode: 0o755 });git(repo, "add", "bin/mso"); git(repo, "commit", "-q", "-m", "new cli"); const newer = git(repo, "rev-parse", "HEAD"); git(repo, "push", "-q", "origin", "main");git(repo, "reset", "--hard", "-q", old);- fs.writeFileSync(path.join(bin, "systemctl"), "#!/bin/sh\nexit 3\n", { mode: 0o755 });+ const serviceRoot = options.activeService === "same" ? repo : options.activeService === "other" ? path.join(root, "other-service") : "";+ if (serviceRoot && serviceRoot !== repo) fs.mkdirSync(serviceRoot, { recursive: true });+ fs.writeFileSync(path.join(bin, "systemctl"), `#!/bin/sh+if [ "$1" = is-active ]; then [ -n "${serviceRoot}" ] && exit 0; exit 3; fi+if [ "$1" = show ]; then printf '%s\n' "${serviceRoot}"; exit 0; fi+if [ "$1" = --user ]; then exit 1; fi+exit 3+`, { mode: 0o755 });const failOnce = path.join(root, "fail-install-once");fs.writeFileSync(path.join(bin, "bun"), `#!/bin/shprintf 'bun %s\\n' "$*" >> "${capture}"@@ -58,6 +65,18 @@ describe("mso update without a running web API", () => {expect(calls).toContain("node node_modules/next/dist/bin/next build");expect(calls).toContain("gateway runtime-stop");expect(calls).toContain("gateway local-start");+ const status = execFileSync(SCRIPT, ["status"], { env: f.env, encoding: "utf8" });+ expect(status).toContain("is up to date");+ expect(status).not.toContain("deployment verification/restart is pending");+ });++ it("refuses update handoff when the active mso.service belongs to another checkout", () => {+ const f = fixture({ activeService: "other" });+ const out = require("node:child_process").spawnSync(SCRIPT, [], { env: f.env, encoding: "utf8" });+ expect(out.status).not.toBe(0);+ expect(out.stderr).toContain("active mso.service belongs to");+ expect(out.stderr).toContain("not this checkout");+ expect(fs.existsSync(f.capture)).toBe(false);});it("retries an incomplete offline deployment even after HEAD already reached origin/main", () => {