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(audit): stop a test run appending to the owner's forensic trail

Rahman6318ff159da4
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index be81c08b..ec1ccbbf 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -8,6 +8,56 @@ Running log of what shipped each phase. Newest at top.
> Read those phases as history. **This file is the source of truth for what exists** —
> `ARCHITECTURE.md` is no longer maintained and carries a stale-warning banner.
+## 2026-08-10 (mcp, follow-up) — the trail the MCP tools were bypassing (DONE)
+
+Shipping the MCP server, the security story told to the owner was "scope is the
+containment, revoke is the kill switch". Both true, both weak without the third
+thing — seeing what already went through — and that was **missing**.
+
+`audit()` is called at the ROUTE layer for `/api/v1`. MCP tools call `lib/host`
+DIRECTLY (deliberately: that is how they inherit the path bounds and the credential
+denylist), so every `fs.write` / `fs.delete` / `fs.move` / `fs.copy` / `fs.mkdir` /
+`exec.run` / `camoufox.power` that arrived over MCP was **absent from
+`~/.mso/audit.log`, the only forensic record there is.**
+
+The dispatcher records it now — one place, not per tool. `McpTool.audit` names the
+action and which argument is the target; `dispatch()` writes it with
+`actor: mcp:<id>` (the same id Settings and `mso mcp list` show, so a line maps back
+to the revoke button) plus `meta.via="mcp"` and the acting scope. Failures too, with
+the reason, so a blocked path is visible rather than silent.
+
+A scope refusal writes `mcp.denied`. Nothing happened, which is exactly why it is
+worth a line: **a `read` connector repeatedly reaching for `exec_run` is what a
+prompt-injected model looks like from the outside**, and this is the only place that
+signal exists. Reads stay unlogged — bounded, high-volume, same rule the routes
+follow, and logging them would bury the lines that matter.
+
+`readAuditTail()` had had NO reader outside its own test since it was written, so
+the trail was unreadable without `cat`. Added `GET /api/v1/sys/audit` (session-gated,
+prefix + actor filters), `mso audit [n] [prefix]`, and a "Recent MCP activity" list
+in Settings → MCP. **Deliberately no MCP tool for any of it**: the trail records what
+every token did, and letting a token read it would let a compromised one check
+whether it had been noticed.
+
+Two tools added, tiered by blast radius rather than by which layer they land in:
+`apps_logs` is READ (a daemon's journal changes nothing, so "why is hermes down?" no
+longer costs a shell) and `apps_power` is WRITE, not exec (three verbs against known
+units — restarting a daemon should not mean handing over the ability to run
+anything). The catalog split at the 220-line ceiling along the same tiering:
+`tool-kit.ts` (shape + arg helpers), `tools-read.ts`, `tools.ts` (write/exec +
+assembly).
+
+**A bug this found in itself:** running the suite after wiring the dispatcher but
+before mocking `audit` put two real `mcp.denied` lines into the owner's live
+`~/.mso/audit.log` at 08:49:50. They are left in place — editing a tamper-evident
+log to hide your own noise is the wrong instinct — and `writeLine` now refuses the
+default path under `VITEST` unless `OS_AUDIT_LOG` is stubbed, with a regression test.
+
+Verified on the live :4005 build: `apps_logs` returns real hermes journal lines at
+read scope, `fs.write` lands in the trail with actor and target, the scope refusal
+lands as `mcp.denied`, `sys_stats` does not appear at all, and `mso audit` reads it
+back.
+
## 2026-08-10 (mcp) — the VPS is drivable from ChatGPT, off by default (DONE)
An MCP server: OAuth 2.1 + PKCE in front of a hand-rolled JSON-RPC endpoint, so
diff --git a/lib/host/audit.test.ts b/lib/host/audit.test.ts
index b8721472..41226be1 100644
--- a/lib/host/audit.test.ts
+++ b/lib/host/audit.test.ts
@@ -165,3 +165,17 @@ describe("readAuditTail", () => {
expect(onlyExec).toHaveLength(2);
});
});
+
+describe("test-run guard", () => {
+ it("never appends to the default ~/.mso/audit.log from a test", async () => {
+ // Regression: dispatch.test.ts exercised the MCP dispatcher, the dispatcher
+ // audits, and two lines landed in the owner's real trail. Any suite that
+ // forgets to stub OS_AUDIT_LOG now writes nowhere instead of into their log.
+ vi.stubEnv("OS_AUDIT_LOG", "");
+ const home = path.join(os.homedir(), ".mso", "audit.log");
+ const before = await fs.readFile(home, "utf8").catch(() => "");
+ await audit({ action: "exec.run", target: "should-never-be-written" });
+ const after = await fs.readFile(home, "utf8").catch(() => "");
+ expect(after).toBe(before);
+ });
+});
diff --git a/lib/host/audit.ts b/lib/host/audit.ts
index 2b3df366..fe5fd385 100644
--- a/lib/host/audit.ts
+++ b/lib/host/audit.ts
@@ -121,6 +121,12 @@ export async function readAuditTail(opts?: { prefix?: string; limit?: number }):
let _writeChain: Promise<void> = Promise.resolve();
async function writeLine(line: string): Promise<void> {
+ // A test run must never append to the OWNER's forensic trail. This is not
+ // hypothetical: on 2026-08-10 two `mcp.denied` lines from lib/mcp/dispatch.test.ts
+ // landed in a real ~/.mso/audit.log, because that suite exercises the dispatcher
+ // and the dispatcher audits. audit.test.ts always stubs OS_AUDIT_LOG at a temp
+ // path, so this only silences the callers that forgot to.
+ if (process.env.VITEST && !process.env.OS_AUDIT_LOG) return;
const file = auditPath();
try {
await fs.mkdir(path.dirname(file), { recursive: true, mode: 0o700 });