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): fail closed on mutable managed-app updates

Abdurrahman Fakhruld2d850e0e1ef
diff --git a/lib/managed-apps/update.test.ts b/lib/managed-apps/update.test.ts
index 6e40f3d0..12ff32cb 100644
--- a/lib/managed-apps/update.test.ts
+++ b/lib/managed-apps/update.test.ts
@@ -94,7 +94,7 @@ describe("checkUpdate normalises two CLIs that agree on nothing", () => {
// carrying a commit count dressed up as one.
expect(status.latestVersion).toBeNull();
expect(status.channel).toMatchObject({ value: "main", kind: "branch", switchable: false, available: [] });
- expect(status.capabilities).toMatchObject({ channel: false, dryRun: false, apply: true });
+ expect(status.capabilities).toMatchObject({ channel: false, dryRun: false, apply: false });
});
it("reads OpenClaw's JSON into the same shape", async () => {
@@ -106,7 +106,7 @@ describe("checkUpdate normalises two CLIs that agree on nothing", () => {
expect(status.updateAvailable).toBe(true);
expect(status.channel).toMatchObject({ value: "stable", kind: "channel", switchable: true });
expect(status.channel.available).toEqual(["stable", "extended-stable", "beta", "dev"]);
- expect(status.capabilities).toMatchObject({ channel: true, dryRun: true });
+ expect(status.capabilities).toMatchObject({ channel: false, dryRun: false, apply: false });
});
it("answers 'not installed' with the command to run, and offers nothing to click", async () => {
@@ -120,49 +120,17 @@ describe("checkUpdate normalises two CLIs that agree on nothing", () => {
});
});
-describe("a backup gates the update it is protecting", () => {
- it("snapshots the state dir first, then runs the update", async () => {
- await recorder("hermes");
- const job = await settle(await startUpdate("hermes"));
-
- expect(job.status).toBe("succeeded");
- expect(await recorded("hermes")).toEqual(["update", "--yes"]);
- const [backup] = await listBackups("hermes");
- expect(backup.reason).toBe("pre-update");
- expect(backup.files).toBe(1);
- expect(await fs.readFile(path.join(home, ".mso", "backups", "hermes", backup.id, "config.yaml"), "utf8")).toBe("state: kept\n");
- // Order is visible in the transcript: the backup lines land before the
- // child's first byte because `prepare` runs before anything spawns.
- expect(job.log.indexOf("pre-update backup")).toBeLessThan(job.log.indexOf("done"));
- expect(job.log).toContain("not in the backup");
- });
-
- it("aborts the update when the backup fails, without spawning anything", async () => {
- await recorder("hermes");
- await fs.rm(path.join(home, ".hermes"), { recursive: true }); // nothing to copy
- const job = await settle(await startUpdate("hermes"));
-
- expect(job.status).toBe("failed");
- expect(job.error).toContain("pre-update backup failed, nothing was run");
- expect(job.exitCode).toBeNull();
- expect(await recorded("hermes")).toEqual([]); // the CLI was never invoked
+describe("mutable upstream updates fail closed", () => {
+ it.each(["hermes", "openclaw"] as const)("refuses %s apply before any job or backup exists", async (id) => {
+ await recorder(id);
+ await expect(startUpdate(id)).rejects.toThrow(/immutable artifact target and digest/);
+ expect(await recorded(id)).toEqual([]);
+ expect(await listManagedAppJobs(id)).toEqual([]);
+ expect(await listBackups(id)).toEqual([]);
});
- // The UI polls a job to a terminal status and then starts the next operation
- // (backup then update, restore then pin). That sequence used to lose a race
- // with the job record's own flush and fail with a lock error nobody held.
- it("lets the next operation start the instant the previous one reads as finished", async () => {
- await recorder("openclaw");
- for (let i = 0; i < 8; i += 1) await settle(await startUpdate("openclaw", { dryRun: true }));
- });
-
- it("skips the backup for a dry run, which writes nothing to snapshot", async () => {
- await recorder("openclaw");
- const job = await settle(await startUpdate("openclaw", { dryRun: true }));
-
- expect(job.status).toBe("succeeded");
- expect(await recorded("openclaw")).toEqual(["update", "--yes", "--dry-run", "--json"]);
- expect(await listBackups("openclaw")).toEqual([]);
+ it("still permits the reviewed 9Router update path", async () => {
+ await expect(startUpdate("9router")).rejects.not.toThrow(/immutable artifact target and digest/);
});
});
@@ -200,19 +168,16 @@ describe("uninstall needs the operator to type the app id", () => {
});
describe("channel switching", () => {
- it("is an update run for OpenClaw, because upstream persists it no other way", async () => {
+ it("does not execute OpenClaw's mutable channel updater", async () => {
await recorder("openclaw");
- const job = await settle(await setChannel("openclaw", "beta"));
-
- expect(await recorded("openclaw")).toEqual(["update", "--yes", "--channel", "beta"]);
- expect(job.kind).toBe("update");
- expect((await listBackups("openclaw"))[0]?.reason).toBe("pre-update");
+ await expect(setChannel("openclaw", "beta")).rejects.toThrow(/immutable artifact target and digest/);
+ expect(await recorded("openclaw")).toEqual([]);
});
- it("is refused for Hermes, whose --branch rewrites a working tree instead", async () => {
+ it("is refused for Hermes and invalid OpenClaw channels", async () => {
await recorder("hermes");
await expect(setChannel("hermes", "beta")).rejects.toThrow("channel switching is not supported for hermes");
- await expect(setChannel("openclaw", "nightly")).rejects.toThrow("unsupported update channel");
+ await expect(setChannel("openclaw", "nightly")).rejects.toThrow(/immutable artifact target and digest|unsupported update channel/);
expect(await recorded("hermes")).toEqual([]);
});
});
@@ -243,12 +208,8 @@ describe("a rollback never undoes its own restore", () => {
// OpenClaw's pin reinstalls an npm package and never touches the state dir
// the restore just wrote, so the two compose and the pin stays offered.
await recorder("openclaw");
- const pinned = await startRollback("openclaw", "2026-07-25T10-11-12-345Z", "2026.7.1-2");
- expect(pinned.argv.slice(1)).toEqual(["update", "--yes", "--tag", "2026.7.1-2"]);
- await settle(pinned);
- // Both jobs name a snapshot that does not exist, so `prepare` fails and the
- // pin never spawns (the restore's own probes may still have) — the argv is
- // what this test is about.
+ await expect(startRollback("openclaw", "2026-07-25T10-11-12-345Z", "2026.7.1-2"))
+ .rejects.toThrow(/immutable artifact target and digest/);
expect(await recorded("openclaw")).not.toContain("update");
});
});
@@ -299,7 +260,7 @@ describe("reading the status never probes", () => {
expect(cold.checkedAt).toBeNull(); // "nobody has asked yet" — not a version
expect(cold.currentVersion).toBeNull();
// What the app supports is still declared, so the panel can render controls.
- expect(cold.capabilities).toMatchObject({ check: true, apply: true, uninstall: true });
+ expect(cold.capabilities).toMatchObject({ check: true, apply: false, channel: false, dryRun: false, uninstall: true });
// THE point: a read spawns nothing. `hermes update --check` git-fetches the
// operator's own checkout twice, and this verb sits outside the CSRF gate,
// reachable from every sibling origin that shares the session cookie.
diff --git a/lib/managed-apps/update.ts b/lib/managed-apps/update.ts
index c56fbe98..6f8174b5 100644
--- a/lib/managed-apps/update.ts
+++ b/lib/managed-apps/update.ts
@@ -28,6 +28,21 @@ const CHECK_CACHE_MS = 60_000;
const cache = new Map<ManagedAppId, ManagedAppUpdateStatus>();
+function safeCapabilities(id: ManagedAppId, capabilities = updateAdapter(id).capabilities) {
+ if (id === "9router") return capabilities;
+ // Hermes/OpenClaw upstream update commands fetch mutable branch/channel/tag
+ // content and execute it before MSO can verify repository-owned bytes. Until
+ // a reviewed release artifact + digest is committed, discovery stays enabled
+ // but apply/channel/dry-run update execution fails closed.
+ return { ...capabilities, apply: false, dryRun: false, channel: false };
+}
+
+function assertVerifiedUpdatePath(id: ManagedAppId): void {
+ if (id !== "9router") {
+ throw new Error(`${id} automated update is disabled until a reviewed immutable artifact target and digest are committed`);
+ }
+}
+
/** Absolute path to the app's CLI. Resolved rather than trusted to PATH so the
* argv the job records is the exact binary that ran, and a missing CLI fails
* here with a readable message instead of as a child-process ENOENT. */
@@ -59,7 +74,7 @@ function unavailable(id: ManagedAppId, error: string): ManagedAppUpdateStatus {
// the omission cannot read as one: a rollback is `restore.ts` copying files
// in-process, so it needs no CLI and stays available precisely when a
// broken install makes it most useful.
- capabilities: { ...capabilities, check: false, apply: false, dryRun: false, channel: false, uninstall: false, rollback: true },
+ capabilities: { ...safeCapabilities(id, capabilities), check: false, apply: false, dryRun: false, channel: false, uninstall: false, rollback: true },
checkedAt: new Date().toISOString(),
error,
};
@@ -77,7 +92,7 @@ export function cachedUpdateStatus(id: ManagedAppId): ManagedAppUpdateStatus {
return {
applicationId: id, currentVersion: null, latestVersion: null, updateAvailable: null, detail: null,
channel: { value: null, kind: null, available: [], switchable: false, reason: null },
- installKind: null, capabilities: updateAdapter(id).capabilities, checkedAt: null, error: null,
+ installKind: null, capabilities: safeCapabilities(id), checkedAt: null, error: null,
};
}
@@ -96,7 +111,7 @@ export async function checkUpdate(id: ManagedAppId, force = false): Promise<Mana
let status: ManagedAppUpdateStatus;
try {
const probe = await adapter.probe(await resolveProgram(getManagedAppDefinition(id).command));
- status = { applicationId: id, ...probe, capabilities: adapter.capabilities, checkedAt: new Date().toISOString() };
+ status = { applicationId: id, ...probe, capabilities: safeCapabilities(id, adapter.capabilities), checkedAt: new Date().toISOString() };
} catch (error) {
status = unavailable(id, message(error));
}
@@ -142,6 +157,7 @@ async function snapshot(definition: ManagedAppDefinition, reason: ManagedAppBack
/** Update, or preview one. `dryRun` skips the backup on purpose: a preview
* writes nothing, and copying 366 MB to predict a no-op is theatre. */
export async function startUpdate(id: ManagedAppId, options: ManagedAppUpdateOptions = {}): Promise<ManagedAppJob> {
+ assertVerifiedUpdatePath(id);
const definition = getManagedAppDefinition(id);
const argv = updateAdapter(id).updateArgv(await resolveProgram(definition.command), options);
return startManagedAppJob({
@@ -160,6 +176,7 @@ export async function startUpdate(id: ManagedAppId, options: ManagedAppUpdateOpt
export async function setChannel(id: ManagedAppId, channel: string): Promise<ManagedAppJob> {
const adapter = updateAdapter(id);
if (!adapter.capabilities.channel) throw new Error(`channel switching is not supported for ${id}`);
+ assertVerifiedUpdatePath(id);
return startUpdate(id, { channel: assertChannel(channel) });
}
@@ -206,7 +223,8 @@ export async function startRollback(id: ManagedAppId, backupId: string, pin?: st
// which auto-stashes the very files the restore just wrote back (update-cli.ts)
// — a rollback that quietly undoes itself and still reports success.
if (pin && !adapter.pin) throw new Error(`pinning a version during a rollback is not supported for ${id}: its pin switches the git checkout, which would stash the restored files`);
- const argv = pin && adapter.pin ? [await resolveProgram(getManagedAppDefinition(id).command), "update", "--yes", ...adapter.pin(pin)] : [];
+ if (pin) throw new Error(`pinning during rollback is disabled until ${id} has a reviewed immutable artifact target and digest`);
+ const argv: string[] = [];
return startManagedAppJob({
applicationId: id,
kind: "restore",