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(install): make bootstrap handoff truncation-safe

Rahmanb97b6f32c0e2
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 7ac80129..4c79985e 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -8,6 +8,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `install` make bootstrap handoff truncation-safe
- `install` make one-line bootstrap atomic
- `install` bind readiness to runtime instance
- `install` preserve caller path semantics
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index 96336b74..6f86c1c0 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -61,7 +61,9 @@ not exist.
The public `scripts/install.sh` is now an intentionally small bootstrap. It downloads the complete
`scripts/install-core.sh` to an owner-private temporary file first, retries the transfer, requires
a minimum payload size and exact EOF marker, verifies the committed SHA-256, runs `bash -n`, and
-only then executes the core with the original arguments. The core carries phase-only error
+only then hands off with a final `exec`. There is deliberately no earlier "done" assignment: any
+normal bootstrap exit before that `exec` is converted to a non-zero truncation failure, including
+a syntactically complete network prefix. The core carries phase-only error
reporting (no raw command/secret echo). A second clean-image reproduction found that `bin/mso` also
requires `jq`: Node and Bun alone were not enough, and the old installer never installed that CLI
runtime dependency. The core now verifies/installs `curl`, `jq` and the required coreutils before
diff --git a/lib/install-contract.test.ts b/lib/install-contract.test.ts
index f7c6bb80..435c5316 100644
--- a/lib/install-contract.test.ts
+++ b/lib/install-contract.test.ts
@@ -26,12 +26,33 @@ describe("one-line installer contract", () => {
expect(bootstrap).toContain("installer payload is unexpectedly short");
expect(bootstrap).toContain("EOF marker missing");
expect(bootstrap).toContain('bash -n "$TMP_INSTALLER"');
- expect(bootstrap).toContain('bash "$TMP_INSTALLER" "$@"');
+ expect(bootstrap).toContain('exec bash /proc/self/fd/3 "$@"');
const declared = bootstrap.match(/CORE_SHA256="([0-9a-f]{64})"/)?.[1];
expect(declared).toBe(crypto.createHash("sha256").update(core).digest("hex"));
expect(core.toString("utf8").trimEnd().endsWith("# MSO_INSTALLER_CORE_EOF")).toBe(true);
});
+ it("rejects a syntactically complete bootstrap prefix before the final exec handoff", () => {
+ const bootstrap = fs.readFileSync(BOOTSTRAP, "utf8");
+ const cutoff = bootstrap.indexOf('exec bash /proc/self/fd/3 "$@"');
+ expect(cutoff).toBeGreaterThan(0);
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mso-bootstrap-prefix-"));
+ try {
+ const truncated = path.join(dir, "install.sh");
+ // Stop after TMP_INSTALLER='' — a syntactically complete prefix that used to
+ // be able to return 0 when a completion marker was set before handoff.
+ fs.writeFileSync(truncated, bootstrap.slice(0, cutoff));
+ const result = spawnSync("bash", [truncated, "--help"], {
+ encoding: "utf8",
+ env: { ...process.env, MSO_INSTALL_CORE_URL: `file://${CORE}` },
+ });
+ expect(result.status).toBe(97);
+ expect(result.stderr).toContain("before verified-core handoff");
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
it("runs the verified local core and rejects a syntactically complete truncated payload", () => {
const env = { ...process.env, MSO_INSTALL_CORE_URL: `file://${CORE}` };
const help = execFileSync("bash", [BOOTSTRAP, "--help"], { encoding: "utf8", env });
diff --git a/scripts/install.sh b/scripts/install.sh
index 924fcf38..58c31b99 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -13,15 +13,18 @@ umask 077
CORE_URL="${MSO_INSTALL_CORE_URL:-https://raw.githubusercontent.com/rahmanef63/mso/main/scripts/install-core.sh}"
CORE_SHA256="913350997e568a279c6582e752d38151f20798cb1f1e471b557aba06b71821ad"
CORE_EOF='# MSO_INSTALLER_CORE_EOF'
-BOOTSTRAP_DONE=0
TMP_INSTALLER=''
bootstrap_exit() {
rc=$?
trap - EXIT
[ -z "$TMP_INSTALLER" ] || rm -f "$TMP_INSTALLER"
- if [ "$rc" -eq 0 ] && [ "$BOOTSTRAP_DONE" -ne 1 ]; then
- printf 'mso installer bootstrap ended before verification completed; retry the download.\n' >&2
+ # The bootstrap has exactly one success path: the final `exec` replaces this
+ # process with the verified core. Therefore ANY normal return from this streamed
+ # bootstrap means the response ended before handoff, even if the last complete
+ # prefix happened to have status 0.
+ if [ "$rc" -eq 0 ]; then
+ printf 'mso installer bootstrap ended before verified-core handoff; retry the download.\n' >&2
rc=97
fi
exit "$rc"
@@ -42,9 +45,10 @@ ACTUAL_SHA="$(sha256sum "$TMP_INSTALLER" | awk '{print $1}')"
[ "$ACTUAL_SHA" = "$CORE_SHA256" ] || fail 'installer payload hash mismatch (main may have changed during download); retry.'
bash -n "$TMP_INSTALLER" || fail 'installer payload failed shell syntax validation.'
-BOOTSTRAP_DONE=1
-set +e
-bash "$TMP_INSTALLER" "$@"
-rc=$?
-set -e
-exit "$rc"
+# Keep the verified payload alive on an fd, unlink its pathname, then replace this
+# streamed bootstrap process. If the network stream ends before the final exec,
+# the EXIT trap above converts even a syntactically complete prefix into failure.
+exec 3<"$TMP_INSTALLER"
+rm -f "$TMP_INSTALLER"
+TMP_INSTALLER=''
+exec bash /proc/self/fd/3 "$@"