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(workflows): close source isolation bypasses
Rahmanc496e5c5ec5e
diff --git a/docs/SOURCE-CONCURRENCY.md b/docs/SOURCE-CONCURRENCY.mdindex 18efbe5d..43904ef4 100644--- a/docs/SOURCE-CONCURRENCY.md+++ b/docs/SOURCE-CONCURRENCY.md@@ -29,6 +29,20 @@ user request7. A worktree is removed only after unique tracked/untracked work is proven preserved and accounted for.8. Release evidence records candidate SHA, integrated SHA, deployed SHA and live SHA separately.+## Mutation-surface classification++Source isolation is about protecting repository/source authority, not relocating every durable control-plane store into a Git worktree.++| Surface | Classification during isolated source workflow | Rule |+|---|---|---|+| `fs_*`, shell, project functions | Source/host mutation | Must target the task worktree; canonical/implicit cwd is refused. |+| Project MCP config/calls, project assets, project-agent write/exec, project flow run/manage, Tool Forge promotion | Project source/config or project-code execution | Must resolve to the task worktree. Canonical project targets fail closed. |+| `.mso/KNOWLEDGE.md`, `.agent/` memory/evidence/recipes/scripts | Canonical private project metadata | Remain project-private/canonical and gitignored; they must not authorize source writes or destructive cleanup. |+| Workflow graph private store, session/artifact indexes, organization, local/A2A messages | Control-plane private state | Stay in their existing private authority store; no worktree redirection. |+| Project database calls, integrations and infrastructure providers | External/provider state | Keep provider-scoped authorization/concurrency rules; worktree isolation does not replace those boundaries. |++Dynamic/project automation does not create an escape hatch: any downstream source-facing tool is still workspace-bound, and project flow execution itself must select the owned worktree. Read-only discovery may inspect canonical state.+## Remote protection targetGitHub is code storage and a remote policy boundary; MSO/Batonly may remain the CI/CD executor. Protect `main` with a ruleset/branch policy that, where account/repository capabilities allow:diff --git a/lib/mcp/tools-flows.ts b/lib/mcp/tools-flows.tsindex 1592a272..49739f9e 100644--- a/lib/mcp/tools-flows.ts+++ b/lib/mcp/tools-flows.ts@@ -17,6 +17,7 @@ import { createWorkflowDataTable, deleteWorkflowDataTable, deleteWorkflowDataTabimport { optimizeWorkflowGraph } from "@/lib/workflow/graph-optimizer";import { createJevWorkflowOptimizerEvaluator } from "@/lib/workflow/jev-optimizer";import { resolveJevIntegrationConfig } from "@/lib/workflow/jev-integration";+import { requireWorkflowProjectTarget } from "./workflow-workspace-guard";const project = { type: "string", maxLength: 4096 };const flow = { type: "string", maxLength: 64 };@@ -42,6 +43,7 @@ export const FLOW_TOOLS: McpTool[] = [inputSchema: S({ project, flow, input: { type: "object", additionalProperties: true }, idempotency_key: { type: "string", minLength: 1, maxLength: 128 } }, ["project", "flow", "input", "idempotency_key"]),run: async (a, context) => {const catalog = await flowCatalog(str(a, "project"), str(a, "flow"));+ await requireWorkflowProjectTarget(context, catalog.project.path);const { TOOLS_BY_NAME } = await import("./tools");return startFlow(catalog.definitions[0], catalog.project.id, a.input, str(a, "idempotency_key"), context, name => TOOLS_BY_NAME.get(name));} },@@ -57,11 +59,12 @@ export const FLOW_TOOLS: McpTool[] = [annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false },actionContract: { phase: "mutate", target: "project-flow", sourceOfTruth: "live", discover: ["flow_catalog"], validators: ["flow-definition", "revision"], verify: ["flow_catalog"], confirmation: "contextual", concurrency: "revision", presentation: "structured" }, audit: { action: "fs.write", targetArg: "project" },inputSchema: S({ project, flow, action: { type: "string", enum: ["upsert", "delete"] }, revision: { type: "string" }, definition: { type: "object", additionalProperties: true } }, ["project", "flow", "action", "revision"]),- run: async a => {+ run: async (a, context) => {const id = str(a, "flow");if (BUILTIN_FLOWS.some(flow => flow.id === id)) throw new Error("built-in flow is immutable");if (a.action !== "upsert" && a.action !== "delete") throw new Error("action must be upsert or delete");const catalog = await flowCatalog(str(a, "project"));+ await requireWorkflowProjectTarget(context, catalog.project.path);return manageProjectFlow(catalog.project.path, { action: a.action, id, flow: a.definition, revision: str(a, "revision") });} },{ name: "workflow_graph", title: "Workflow Graph", scope: "exec", limit: { key: "workflow.graph", max: 20, windowMs: 60_000 },diff --git a/lib/mcp/tools-forge-workspace-guard.test.ts b/lib/mcp/tools-forge-workspace-guard.test.tsnew file mode 100644index 00000000..63b054f4--- /dev/null+++ b/lib/mcp/tools-forge-workspace-guard.test.ts@@ -0,0 +1,25 @@+import { beforeEach, describe, expect, it, vi } from "vitest";++const guard = vi.fn();+const getForgeCandidate = vi.fn();+vi.mock("./workflow-workspace-guard", () => ({ requireWorkflowProjectTarget: guard }));+vi.mock("@/lib/forge/store", () => ({+ getForgeCandidate, listForgeCandidates:vi.fn(), publicForgeCandidate:vi.fn((value)=>value), updateForgeCandidate:vi.fn(),+}));+vi.mock("@/lib/forge/evaluate", () => ({ evaluateForgeCandidate:vi.fn() }));+vi.mock("@/lib/forge/promote", () => ({ promoteForgeCandidate:vi.fn() }));+vi.mock("@/lib/forge/proposal", () => ({ proposeForgeCandidate:vi.fn() }));+vi.mock("@/lib/workflow", () => ({ listLearnedRecipes:vi.fn(async()=>[]) }));++const { FORGE_TOOLS } = await import("./tools-forge");++describe("Tool Forge source workspace guard", () => {+ beforeEach(() => { guard.mockReset(); getForgeCandidate.mockReset(); });+ it("checks the candidate project path before promotion evaluation or write", async () => {+ getForgeCandidate.mockResolvedValue({ id:"cand-1", state:"evaluated", projectPath:"/canonical/project" });+ guard.mockRejectedValue(new Error("source-isolated"));+ const promote = FORGE_TOOLS.find((tool) => tool.name === "tool_forge_promote")!;+ await expect(promote.run({ candidate_id:"cand-1", confirmation:"PROMOTE cand-1" }, { actor:"owner", scope:"exec" })).rejects.toThrow("source-isolated");+ expect(guard).toHaveBeenCalledWith(expect.objectContaining({ actor:"owner" }), "/canonical/project");+ });+});diff --git a/lib/mcp/tools-forge.ts b/lib/mcp/tools-forge.tsindex 7e9f123c..68000e18 100644--- a/lib/mcp/tools-forge.ts+++ b/lib/mcp/tools-forge.ts@@ -6,6 +6,7 @@ import { getForgeCandidate, listForgeCandidates, publicForgeCandidate, updateForimport { listLearnedRecipes } from "@/lib/workflow";import { type McpTool, S, str, opt } from "./tool-kit";import { toolsetInfo } from "./toolset";+import { requireWorkflowProjectTarget } from "./workflow-workspace-guard";function forgeOwner(context: { recipeActor?: string; actor?: string }): string {const owner = context.recipeActor ?? context.actor;@@ -125,6 +126,7 @@ export const FORGE_TOOLS: McpTool[] = [const current = await getForgeCandidate(id, owner);if (!current) throw new Error("forge candidate not found");if (current.state === "promoted") throw new Error("forge candidate is already promoted");+ await requireWorkflowProjectTarget(context, current.projectPath);const evaluation = await freshEvaluation(current);if (!evaluation.passed) {await updateForgeCandidate(id, owner, (candidate) => ({ ...candidate, state: "draft", evaluation, updatedAt: new Date().toISOString() }));diff --git a/lib/mcp/tools-project-assets.ts b/lib/mcp/tools-project-assets.tsindex 9bba96a1..7ac16189 100644--- a/lib/mcp/tools-project-assets.ts+++ b/lib/mcp/tools-project-assets.ts@@ -3,6 +3,7 @@ import { readSessionArtifact } from "@/lib/agent/artifacts";import { attachProjectAsset } from "@/lib/host/project-assets";import { resolveProjectHint } from "@/lib/host/projects-api";import { type McpTool, S, str, opt } from "./tool-kit";+import { requireWorkflowProjectTarget } from "./workflow-workspace-guard";export const PROJECT_ASSET_TOOLS: McpTool[] = [{name: "project_asset_attach", title: "Attach Asset to Project", scope: "write",description: "Copy one owned session image/JSON artifact into an exact project at relative_path. Verifies source checksum and creates the destination atomically; same bytes are idempotent, different existing bytes are refused. Project copy survives session cleanup. Preview with session_artifacts; manage project files with fs_*.",@@ -14,6 +15,7 @@ export const PROJECT_ASSET_TOOLS: McpTool[] = [{run: async (a, context) => {const project = await resolveProjectHint(str(a, "project"));if (!project || project.matchedBy === "fuzzy") throw new Error("exact project required");+ await requireWorkflowProjectTarget(context, project.path);const owner = await ownedArtifactSession(context.principal, opt(a, "session_id") || context.sessionId);const source = await readSessionArtifact(owner, str(a, "artifact_id"));return { project: project.id, artifactId: source.entry.id, ...await attachProjectAsset(project.path, str(a, "relative_path"), source.bytes, source.entry.mimeType) };diff --git a/lib/mcp/tools-project-mcp-manage.ts b/lib/mcp/tools-project-mcp-manage.tsindex fcd2c113..03a7ecf0 100644--- a/lib/mcp/tools-project-mcp-manage.ts+++ b/lib/mcp/tools-project-mcp-manage.ts@@ -1,6 +1,7 @@import { inspectProjectMcp, manageProjectMcp } from "@/lib/host/project-mcp-manage";import { resolveMcpInstallTarget } from "@/lib/host/mcp-install-target";import { type McpTool, S, str } from "./tool-kit";+import { requireWorkflowProjectTarget } from "./workflow-workspace-guard";export const PROJECT_MCP_MANAGE_TOOLS: McpTool[] = [{name: "project_mcp_manage", title: "Install or Manage MCP", scope: "write",description: "Inspect/install/update/uninstall an MCP binding on one exact project, or project=@host for this MSO host. Host installations never propagate to projects. Fresh projects have no plugin binding and nothing is inherited from parent projects. For reviewed project plugins set plugin=si-coder or plugin=batonly; Batonly also requires an exact MSO credential user/connection. Arbitrary HTTP MCPs still use url. Inspect first for revision; mutations preserve other servers.",@@ -19,11 +20,12 @@ export const PROJECT_MCP_MANAGE_TOOLS: McpTool[] = [{user: { type: "string", description: "Exact credential owner; use together with connection." },connection: { type: "string", description: "Exact private MCP connection; omit both for public MCP." },}, ["project", "action"]),- run: async a => {+ run: async (a, context) => {if (a.plugin !== undefined && !["si-coder", "batonly"].includes(String(a.plugin))) throw new Error("unsupported project plugin");const project = await resolveMcpInstallTarget(str(a, "project"), a.action === "upsert");if (a.action === "inspect") return { project: project.id, installationScope: project.installationScope, ...await inspectProjectMcp(project.path) };if (a.action !== "upsert" && a.action !== "delete") throw new Error("invalid MCP action");+ if (project.installationScope === "project") await requireWorkflowProjectTarget(context, project.path);return { project: project.id, installationScope: project.installationScope, ...await manageProjectMcp(project.path, { action: a.action, server: str(a, "server"), revision: str(a, "revision"),plugin: a.plugin === "si-coder" || a.plugin === "batonly" ? a.plugin : undefined, url: typeof a.url === "string" ? a.url : undefined, user: typeof a.user === "string" ? a.user : undefined, connection: typeof a.connection === "string" ? a.connection : undefined }) };},diff --git a/lib/mcp/tools-project-mcp.ts b/lib/mcp/tools-project-mcp.tsindex d14d975d..6a59aca3 100644--- a/lib/mcp/tools-project-mcp.ts+++ b/lib/mcp/tools-project-mcp.ts@@ -3,6 +3,7 @@ import { callManagedScProvider } from "./managed-sc-call";import { projectMcpResult, projectMcpStructuredProjection } from "@/lib/host/project-mcp-result";import { callProjectMcpTool, listProjectMcpToolPage, publicProjectMcpServers, readProjectMcpServers } from "@/lib/host/projects-api";import { type McpTool, S, str, mcpDirect } from "./tool-kit";+import { requireWorkflowProjectTarget } from "./workflow-workspace-guard";export const PROJECT_MCP_TOOLS: McpTool[] = [{@@ -47,8 +48,9 @@ export const PROJECT_MCP_TOOLS: McpTool[] = [tool: { type: "string", description: "Exact tool name from project_mcp_tools." },arguments: { type: "object", description: "Arguments matching that dynamic tool's input schema.", additionalProperties: true },}, ["project", "server", "tool"]),- run: async (a) => {+ run: async (a, context) => {const project = await resolveMcpInstallTarget(str(a, "project"));+ if (project.installationScope === "project") await requireWorkflowProjectTarget(context, project.path);const managed = await callManagedScProvider(project.path, str(a, "server"), str(a, "tool"), a.arguments ?? {});const out = projectMcpResult(managed.handled ? managed.result : await callProjectMcpTool(project.path, str(a, "server"), str(a, "tool"), a.arguments ?? {}));return mcpDirect(out.content, out.isError, { result: { project: project.id, server: str(a, "server"), tool: str(a, "tool"), output: projectMcpStructuredProjection(out) } }, out.meta);diff --git a/lib/mcp/tools-project-runtime.ts b/lib/mcp/tools-project-runtime.tsindex a3ee50f2..911822e6 100644--- a/lib/mcp/tools-project-runtime.ts+++ b/lib/mcp/tools-project-runtime.ts@@ -4,6 +4,7 @@ import { createProjectAgentTask, getProjectAgentTask, updateProjectAgentTask } fimport { allows, parseScope } from "./scope";import { type McpTool, S, str, opt, READ_ONLY } from "./tool-kit";import { databaseDeployment, selectedProject } from "./tools-project-shared";+import { requireWorkflowProjectTarget } from "./workflow-workspace-guard";export const PROJECT_RUNTIME_TOOLS: McpTool[] = [{@@ -86,6 +87,7 @@ export const PROJECT_RUNTIME_TOOLS: McpTool[] = [const project = await selectedProject(str(a, "project"));const requested = parseScope(a.plan_mode === true ? "read" : (opt(a, "max_scope") ?? "write"));if (!allows(context.scope, requested)) throw new Error(`project agent max_scope ${requested} exceeds caller scope ${context.scope}`);+ if (requested !== "read") await requireWorkflowProjectTarget(context, project.path);const message = str(a, "message"), planMode = a.plan_mode === true;const task = await createProjectAgentTask({ principal: context.principal, sessionId: context.sessionId, project: { id: project.id, name: project.name }, planMode, maxScope: requested });const execute = async () => {diff --git a/lib/mcp/workflow-project-surface-isolation.test.ts b/lib/mcp/workflow-project-surface-isolation.test.tsnew file mode 100644index 00000000..be6da5e6--- /dev/null+++ b/lib/mcp/workflow-project-surface-isolation.test.ts@@ -0,0 +1,92 @@+import { execFileSync } from "node:child_process";+import { promises as fs } from "node:fs";+import os from "node:os";+import path from "node:path";+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";++vi.mock("server-only", () => ({}));++const root = await fs.mkdtemp(path.join(os.tmpdir(), "mso-project-surfaces-"));+const project = path.join(root, "project");+const worktrees = path.join(root, "worktrees");+await fs.mkdir(path.join(project, "src"), { recursive: true });+await fs.writeFile(path.join(project, "package.json"), JSON.stringify({ name: "surface-isolation-fixture" }));+await fs.writeFile(path.join(project, ".gitignore"), ".mso/\n.agent/\n");+await fs.writeFile(path.join(project, "src/value.ts"), "export const value = 1;\n");+const git = (...args: string[]) => execFileSync("git", args, { cwd: project, encoding: "utf8" }).trim();+git("init", "-q", "-b", "main"); git("config", "user.name", "MSO Test"); git("config", "user.email", "[email protected]");+git("add", "."); git("commit", "-qm", "initial");++const previous = {+ read: process.env.OS_FS_READ_ROOTS, write: process.env.OS_FS_WRITE_ROOTS,+ roots: process.env.OS_PROJECT_ROOTS, memory: process.env.OS_SKILL_MEMORY_STORE,+ worktrees: process.env.MSO_AGENT_WORKTREE_ROOT,+};++beforeAll(async () => {+ process.env.OS_FS_READ_ROOTS = root; process.env.OS_FS_WRITE_ROOTS = root;+ process.env.OS_PROJECT_ROOTS = root; process.env.OS_SKILL_MEMORY_STORE = path.join(root, "workflow-memory.json");+ process.env.MSO_AGENT_WORKTREE_ROOT = worktrees;+ const { resetWorkflowStoreCache } = await import("@/lib/workflow"); resetWorkflowStoreCache();+});+afterAll(async () => {+ const keys = { read:"OS_FS_READ_ROOTS", write:"OS_FS_WRITE_ROOTS", roots:"OS_PROJECT_ROOTS", memory:"OS_SKILL_MEMORY_STORE", worktrees:"MSO_AGENT_WORKTREE_ROOT" } as const;+ for (const [key, env] of Object.entries(keys)) {+ const value = previous[key as keyof typeof previous];+ if (value === undefined) delete process.env[env]; else process.env[env] = value;+ }+ const { resetWorkflowStoreCache } = await import("@/lib/workflow"); resetWorkflowStoreCache();+ await fs.rm(root, { recursive: true, force: true });+});++describe("isolated workflow project mutation surfaces", () => {+ it("refuses canonical source-facing project tools and permits the owned worktree target", async () => {+ const { LEARNING_TOOLS } = await import("./tools-learning");+ const { PROJECT_MCP_MANAGE_TOOLS } = await import("./tools-project-mcp-manage");+ const { PROJECT_ASSET_TOOLS } = await import("./tools-project-assets");+ const { PROJECT_MCP_TOOLS } = await import("./tools-project-mcp");+ const { PROJECT_RUNTIME_TOOLS } = await import("./tools-project-runtime");+ const { FLOW_TOOLS } = await import("./tools-flows");+ const start = LEARNING_TOOLS.find((tool) => tool.name === "workflow_start")!;+ const actor = "mcp:project-surface-isolation";+ const started = await start.run({ intent:"change project source and verify it", project, affected_paths:["src/value.ts"] }, { actor, scope:"exec" }) as {+ workflow:{ id:string; orchestration?:{ workspacePath?:string } }+ };+ const workspace = started.workflow.orchestration?.workspacePath!;+ const context = { actor, workflowActor:actor, workflowId:started.workflow.id, principal:actor, sessionId:"session", scope:"exec" as const, capabilities:{} as never };+ const manage = PROJECT_MCP_MANAGE_TOOLS.find((tool) => tool.name === "project_mcp_manage")!;+ const asset = PROJECT_ASSET_TOOLS.find((tool) => tool.name === "project_asset_attach")!;+ const mcpCall = PROJECT_MCP_TOOLS.find((tool) => tool.name === "project_mcp_call")!;+ const projectAgent = PROJECT_RUNTIME_TOOLS.find((tool) => tool.name === "project_agent_run")!;+ const flowRun = FLOW_TOOLS.find((tool) => tool.name === "flow_run")!;+ const flowManage = FLOW_TOOLS.find((tool) => tool.name === "flow_manage")!;++ await expect(manage.run({ project, action:"delete", server:"demo", revision:"x" }, context)).rejects.toThrow(/source-isolated/i);+ await expect(asset.run({ project, artifact_id:"missing", relative_path:"assets/demo.json" }, context)).rejects.toThrow(/source-isolated/i);+ await expect(mcpCall.run({ project, server:"demo", tool:"write", arguments:{} }, context)).rejects.toThrow(/source-isolated/i);+ await expect(projectAgent.run({ project, message:"edit source", max_scope:"write" }, context)).rejects.toThrow(/source-isolated/i);+ await expect(flowRun.run({ project, flow:"cloudflare.dns.ensure", input:{}, idempotency_key:"surface-test" }, context)).rejects.toThrow(/source-isolated/i);+ await expect(flowManage.run({ project, flow:"custom", action:"delete", revision:"x" }, context)).rejects.toThrow(/source-isolated/i);++ const inspected = await manage.run({ project:workspace, action:"inspect" }, context) as { revision:string };+ await expect(manage.run({ project:workspace, action:"upsert", server:"demo", revision:inspected.revision, url:"https://example.com/mcp" }, context)).resolves.toMatchObject({ installationScope:"project" });+ expect(await fs.readFile(path.join(workspace, ".mcp.json"), "utf8")).toContain("example.com/mcp");+ await expect(fs.readFile(path.join(project, ".mcp.json"), "utf8")).rejects.toMatchObject({ code:"ENOENT" });+ expect(git("status", "--porcelain")).toBe("");+ });++ it("keeps ignored project knowledge and repo memory canonical without dirtying source", async () => {+ const { LEARNING_TOOLS } = await import("./tools-learning");+ const { PROJECT_STATE_TOOLS } = await import("./tools-project-state");+ const { PROJECT_MEMORY_TOOLS } = await import("./tools-project-memory");+ const start = LEARNING_TOOLS.find((tool) => tool.name === "workflow_start")!;+ const actor = "mcp:private-project-state";+ const started = await start.run({ intent:"inspect source then preserve project evidence", project, affected_paths:["src/value.ts"] }, { actor, scope:"exec" }) as { workflow:{ id:string } };+ const context = { actor, workflowActor:actor, workflowId:started.workflow.id, scope:"write" as const };+ const knowledge = PROJECT_STATE_TOOLS.find((tool) => tool.name === "project_knowledge_set")!;+ const memory = PROJECT_MEMORY_TOOLS.find((tool) => tool.name === "project_memory_upsert")!;+ await expect(knowledge.run({ project, content:"# Private project context\n" }, context)).resolves.toMatchObject({ path:".mso/KNOWLEDGE.md" });+ await expect(memory.run({ project, kind:"test", title:"Private evidence", summary:"Preserved outside source history." }, context)).resolves.toMatchObject({ kind:"test" });+ expect(git("status", "--porcelain")).toBe("");+ });+});