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(mcp): the audit trail was recording refused commands as successes
Rahman493b29eec9c7
diff --git a/lib/mcp/dispatch.test.ts b/lib/mcp/dispatch.test.tsindex f809ea6a..069d38cd 100644--- a/lib/mcp/dispatch.test.ts+++ b/lib/mcp/dispatch.test.ts@@ -151,7 +151,21 @@ describe("audit trail", () => {it("records exec_run with the command as the target", async () => {await dispatch(call("exec_run", { command: "echo hi" }), "exec", "mcp:abc123");- expect(audited[0]).toMatchObject({ action: "exec.run", target: "echo hi" });+ expect(audited[0]).toMatchObject({ action: "exec.run", target: "echo hi", ok: true, detail: "exit 0" });+ });++ it("records a REFUSED command as exec.blocked, not a successful exec.run", async () => {+ // runCommand refuses by RETURNING {code:126}, not by throwing, so "did not+ // throw" is not success. This shipped wrong on 2026-08-10: a blocked command+ // landed in the trail as ok:true, and exec.blocked could never be emitted over+ // MCP at all. Mirrors app/api/v1/exec/run/route.ts.+ await dispatch(call("exec_run", { command: "rm -rf /" }), "exec", "mcp:abc123");+ expect(audited[0]).toMatchObject({ action: "exec.blocked", ok: false });+ });++ it("records a non-zero exit as a failure, with the code", async () => {+ await dispatch(call("exec_run", { command: "exit 3" }), "exec", "mcp:abc123");+ expect(audited[0]).toMatchObject({ action: "exec.run", ok: false, detail: "exit 3" });});it("does NOT record reads — bounded and high-volume, same rule /api/v1 follows", async () => {diff --git a/lib/mcp/dispatch.ts b/lib/mcp/dispatch.tsindex d05509b8..407dc084 100644--- a/lib/mcp/dispatch.ts+++ b/lib/mcp/dispatch.ts@@ -90,7 +90,14 @@ export async function dispatch(req: RpcRequest, scope: Scope, actor?: string): Pconst target = trail?.targetArg != null ? String(args[trail.targetArg] ?? "") : undefined;try {const result = await tool.run(args);- if (trail) void audit({ action: trail.action, actor, target, ok: true, meta: { via: "mcp", scope } });+ if (trail) {+ // `ok: true` used to be unconditional here, which made the trail lie about+ // the one tool that matters most: runCommand REFUSES a destructive command+ // by RETURNING code 126, so a blocked `rm -rf /` was recorded as a+ // successful exec.run, and `exec.blocked` could never be emitted over MCP.+ const o = trail.outcome?.(result);+ void audit({ action: o?.action ?? trail.action, actor, target, ok: o?.ok ?? true, detail: o?.detail, meta: { via: "mcp", scope } });+ }return ok(id, { content: [{ type: "text", text: typeof result === "string" ? result : JSON.stringify(result) }] });} catch (e) {// A handler failure stays INSIDE result with isError, never as a JSON-RPCdiff --git a/lib/mcp/tool-kit.ts b/lib/mcp/tool-kit.tsindex 8a405f36..22bdf3ee 100644--- a/lib/mcp/tool-kit.ts+++ b/lib/mcp/tool-kit.ts@@ -22,7 +22,17 @@ export interface McpTool {* This exists because MCP tools call lib/host DIRECTLY. The /api/v1 routes* audit at the ROUTE layer, so without this every write, delete and exec that* arrived over MCP would be invisible in the only forensic trail there is. */- audit?: { action: AuditAction; targetArg?: string };+ audit?: {+ action: AuditAction;+ targetArg?: string;+ /** Derive the outcome from the RESULT, for a handler that reports failure by+ * returning rather than throwing. Without it the dispatcher can only record+ * "did not throw", which is a lie for anything that has an exit code.+ * Only exec_run needs this — `setCamoufoxEnabled` throws, and the fs helpers+ * throw, so the catch branch already records those correctly. Deliberately+ * NOT a generic result→outcome mapper: one call site is not a pattern. */+ outcome?: (result: unknown) => { ok: boolean; action?: AuditAction; detail?: string };+ };}export const str = (a: Record<string, unknown>, k: string): string => {diff --git a/lib/mcp/tools.ts b/lib/mcp/tools.tsindex 5f1d4f07..900a7e95 100644--- a/lib/mcp/tools.ts+++ b/lib/mcp/tools.ts@@ -83,7 +83,19 @@ const MUTATE_TOOLS: McpTool[] = [},{name: "exec_run",- audit: { action: "exec.run" as const, targetArg: "command" },+ audit: {+ action: "exec.run" as const,+ targetArg: "command",+ // runCommand REFUSES by returning {code:126, stderr:"refused: …"}, it does not+ // throw — so "the handler did not throw" is not success here. Mirrors+ // app/api/v1/exec/run/route.ts:39-45 exactly; the two must not disagree about+ // what the same command did.+ outcome: (r) => {+ const { code, stderr } = r as { code: number; stderr: string };+ const blocked = code === 126 && stderr.startsWith("refused:");+ return { ok: !blocked && code === 0, action: blocked ? "exec.blocked" : "exec.run", detail: `exit ${code}` };+ },+ },description:"Run a shell command on the VPS as the owner and return stdout, stderr and exit code. " +"FULL HOST POWER — prefer fs_* and sys_* tools whenever they cover the task; they are bounded and " +