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(security): pin Termux guest installer payload

Rahmand4d12c1681fa
diff --git a/lib/platform-support.test.ts b/lib/platform-support.test.ts
index bb3fdbb8..2982e44b 100644
--- a/lib/platform-support.test.ts
+++ b/lib/platform-support.test.ts
@@ -12,6 +12,7 @@ const INSTALL_PAGE = fs.readFileSync(path.join(ROOT, "app/install/page.tsx"), "u
const PLATFORM_TABS = fs.readFileSync(path.join(ROOT, "app/install/platform-tabs.tsx"), "utf8");
const INSTALLER_PATH = path.join(ROOT, "scripts/install.sh");
const INSTALLER = fs.readFileSync(INSTALLER_PATH, "utf8");
+const INSTALL_CORE = fs.readFileSync(path.join(ROOT, "scripts/install-core.sh"), "utf8");
const MACOS_INSTALLER = fs.readFileSync(path.join(ROOT, "scripts/install-macos.sh"), "utf8");
const TERMUX_INSTALLER = fs.readFileSync(path.join(ROOT, "scripts/install-termux.sh"), "utf8");
const WINDOWS_INSTALLER = fs.readFileSync(path.join(ROOT, "scripts/install-windows.ps1"), "utf8");
@@ -99,6 +100,7 @@ describe("MSO platform support contract", () => {
it("pins compatibility bootstraps from the public dispatcher", () => {
expect(INSTALLER).toContain('MACOS_SHA256="' + sha256(MACOS_INSTALLER) + '"');
expect(INSTALLER).toContain('TERMUX_SHA256="' + sha256(TERMUX_INSTALLER) + '"');
+ expect(TERMUX_INSTALLER).toContain('GUEST_INSTALL_SHA256_DEFAULT="' + sha256(INSTALL_CORE) + '"');
expect(INSTALLER).toContain("*/com.termux/files/usr)");
expect(INSTALLER).toContain("MINGW*|MSYS*|CYGWIN*)");
});
diff --git a/scripts/install-termux.sh b/scripts/install-termux.sh
index 425bdfd7..9b0b5802 100755
--- a/scripts/install-termux.sh
+++ b/scripts/install-termux.sh
@@ -6,7 +6,10 @@ umask 077
DISTRO="${MSO_TERMUX_DISTRO:-mso-ubuntu}"
GUEST_USER="${MSO_TERMUX_USER:-mso}"
IMAGE="${MSO_TERMUX_IMAGE:-ubuntu:24.04}"
-INSTALL_URL="${MSO_TERMUX_INSTALL_URL:-https://raw.githubusercontent.com/rahmanef63/mso/main/scripts/install.sh}"
+GUEST_INSTALL_URL_DEFAULT="https://raw.githubusercontent.com/rahmanef63/mso/main/scripts/install-core.sh"
+GUEST_INSTALL_SHA256_DEFAULT="794d8893285c045a8ab608d8c1d2803188b4a2a13058695d6c1fd54520973b65"
+INSTALL_URL="${MSO_TERMUX_INSTALL_URL:-$GUEST_INSTALL_URL_DEFAULT}"
+INSTALL_SHA256="${MSO_TERMUX_INSTALL_SHA256:-$GUEST_INSTALL_SHA256_DEFAULT}"
GUEST_REF="${MSO_TERMUX_REF:-main}"
BUILD_CPUS="${MSO_TERMUX_BUILD_CPUS:-1}"
NODE_HEAP_MB="${MSO_TERMUX_NODE_HEAP_MB:-1536}"
@@ -29,6 +32,10 @@ esac
[[ "$GUEST_REF" =~ ^[a-zA-Z0-9][a-zA-Z0-9._/-]*$ ]] || fail 'invalid MSO ref.'
[[ "$BUILD_CPUS" =~ ^[1-9][0-9]*$ ]] || fail 'MSO_TERMUX_BUILD_CPUS must be a positive integer.'
[[ "$NODE_HEAP_MB" =~ ^[1-9][0-9]*$ ]] || fail 'MSO_TERMUX_NODE_HEAP_MB must be a positive integer.'
+if [ -n "${MSO_TERMUX_INSTALL_URL:-}" ] && [ -z "${MSO_TERMUX_INSTALL_SHA256:-}" ]; then
+ fail 'MSO_TERMUX_INSTALL_SHA256 is required when overriding MSO_TERMUX_INSTALL_URL.'
+fi
+[[ "$INSTALL_SHA256" =~ ^[0-9a-f]{64}$ ]] || fail 'MSO_TERMUX_INSTALL_SHA256 must be a lowercase SHA-256 digest.'
mkdir -p "$(dirname "$INSTALL_LOG")"
touch "$INSTALL_LOG"
@@ -108,7 +115,23 @@ proot-distro login "$DISTRO" --user "$GUEST_USER" -- /usr/bin/env -i \
}
fi
done
- curl -fsSL "$1" | /bin/bash -s -- --no-service --no-onboard
+ TMP_INSTALLER="$(mktemp "$HOME/.mso-install-core.XXXXXX")"
+ cleanup_installer() { rm -f "$TMP_INSTALLER"; }
+ trap cleanup_installer EXIT
+ curl -fsSL --retry 3 --retry-delay 1 --connect-timeout 15 --max-time 180 "$1" -o "$TMP_INSTALLER" || {
+ echo "MSO installer payload download failed." >&2
+ exit 1
+ }
+ ACTUAL_SHA256="$(sha256sum "$TMP_INSTALLER")"
+ ACTUAL_SHA256="${ACTUAL_SHA256%% *}"
+ [ "$ACTUAL_SHA256" = "$2" ] || {
+ echo "MSO installer payload hash mismatch; refusing execution." >&2
+ exit 1
+ }
+ /bin/bash -n "$TMP_INSTALLER"
+ /bin/bash "$TMP_INSTALLER" --no-service --no-onboard
+ cleanup_installer
+ trap - EXIT
[ "$(node -p "process.platform")" = linux ]
[ "$(bun -p "process.platform")" = linux ]
command -v mso >/dev/null 2>&1
@@ -119,7 +142,7 @@ proot-distro login "$DISTRO" --user "$GUEST_USER" -- /usr/bin/env -i \
if [ "$MSO_REF" = main ] && [ -d "$HOME/mso/.git" ]; then
git -C "$HOME/mso" switch -C main origin/main >/dev/null
fi
-' bash "$INSTALL_URL"
+' bash "$INSTALL_URL" "$INSTALL_SHA256"
LAUNCHER="$TERMUX_BIN/mso"
info "installing Termux launcher: $LAUNCHER"
diff --git a/scripts/install-termux.test.ts b/scripts/install-termux.test.ts
index b9a6f297..1c58a642 100644
--- a/scripts/install-termux.test.ts
+++ b/scripts/install-termux.test.ts
@@ -101,7 +101,7 @@ describe("Termux PRoot Linux environment boundary", () => {
const f = fixture(), bin = path.join(f.root, "guest-bin"); fs.mkdirSync(bin);
for (const runtime of ["node", "bun"]) fs.writeFileSync(path.join(bin, runtime), `#!/bin/sh\necho ${runtime === android ? "android" : "linux"}\n`, { mode: 0o755 });
const args = f.readArgs("owner"), body = args[args.indexOf("-c") + 1];
- const guard = body.slice(0, body.indexOf(' curl -fsSL "$1"'));
+ const guard = body.slice(0, body.indexOf(' TMP_INSTALLER="$(mktemp'));
expect(guard).toContain('for runtime in node bun; do');
const result = spawnSync("/bin/bash", ["--noprofile", "--norc", "-c", `${guard}\necho DOWNLOAD_REACHED`], { env: { HOME: f.root, PATH: `${bin}:/usr/bin:/bin`, NODE_ENV: "test" }, encoding: "utf8", timeout: 10000 });
expect(result.status).not.toBe(0);
@@ -110,4 +110,13 @@ describe("Termux PRoot Linux environment boundary", () => {
expect(body).toContain('[ "$(node -p "process.platform")" = linux ]');
expect(body).toContain('[ "$(bun -p "process.platform")" = linux ]');
});
+ it("downloads the Ubuntu guest installer to a file and verifies its pinned SHA-256 before execution", () => {
+ const source = fs.readFileSync(installer, "utf8");
+ expect(source).toContain('GUEST_INSTALL_URL_DEFAULT="https://raw.githubusercontent.com/rahmanef63/mso/main/scripts/install-core.sh"');
+ expect(source).toMatch(/GUEST_INSTALL_SHA256_DEFAULT="[0-9a-f]{64}"/);
+ expect(source).toContain('[ "$ACTUAL_SHA256" = "$2" ]');
+ expect(source).toContain('/bin/bash -n "$TMP_INSTALLER"');
+ expect(source).toContain('/bin/bash "$TMP_INSTALLER" --no-service --no-onboard');
+ expect(source).not.toMatch(/curl[^\n]*\|\s*\/?bin\/bash/);
+ });
});
diff --git a/scripts/install.sh b/scripts/install.sh
index c9a24177..2aeb6d17 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -14,7 +14,7 @@ CORE_URL="${MSO_INSTALL_CORE_URL:-https://raw.githubusercontent.com/rahmanef63/m
CORE_SHA256="794d8893285c045a8ab608d8c1d2803188b4a2a13058695d6c1fd54520973b65"
CORE_EOF='# MSO_INSTALLER_CORE_EOF'
MACOS_SHA256="668ec3c8bbf3ee36dc2ae70952c3ba43c6f73ebc3acd6956fa4be2f65a076bfe"
-TERMUX_SHA256="7e8a07634c2256c2db5970e579d679dd1978f2a8120a4282d206690f37166e13"
+TERMUX_SHA256="ade7528826e50b17d2f288cbc763272441242bb3ab548ad5dcf9ef2c1be01644"
TMP_INSTALLER=''
TMP_PLATFORM=''