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(flows): enforce canonical paths and bounded waits

Rahmana8f6c5659933
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index b10f8879..adb46b10 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -10,6 +10,10 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
- `mcp` add project automation flows and dynamic MCP sessions
+**Fixed**
+
+- `flows` enforce canonical paths and bounded waits
+
## 2026-09-11
**Added**
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index 9a6d513b..b2284eb8 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -1,3 +1,11 @@
+## 2026-09-12 — Hosted flow security checks
+
+The hosted pipeline identified a ShellCheck usage-variable warning and a strict Semgrep
+parser limitation on compact Bash case statements. Flow CLI cases now use ordinary
+multiline syntax and a bounded usage fallback. Shared project containment is expressed
+at the filesystem sink, flow manifests use approved canonical paths, and status waits
+reject noninteger/out-of-range durations before allocating a timer.
+
## 2026-09-12 — Dynamic project MCP and reusable provider flows
Added versioned project automation, shared CLI/MCP execution, durable idempotency receipts,
diff --git a/lib/host/project-candidate.ts b/lib/host/project-candidate.ts
index 1308eebc..026a74da 100644
--- a/lib/host/project-candidate.ts
+++ b/lib/host/project-candidate.ts
@@ -30,14 +30,18 @@ async function validateComponent(parent: string, name: string): Promise<Candidat
if (!name || name === "." || name === ".." || name.includes("/") || name.includes("\\")) return { ok: false, reason: "escape" };
if (name.startsWith(".")) return { ok: false, reason: "hidden" };
const full = path.join(parent, name);
- const stat = await fs.lstat(full).catch(() => null);
- if (!stat) return { ok: false, reason: "missing" };
- if (stat.isSymbolicLink()) return { ok: false, reason: "symlink" };
- if (!stat.isDirectory()) return { ok: false, reason: "not-directory" };
- const uid = currentUid();
- if (uid !== undefined && stat.uid !== uid) return { ok: false, reason: "uid" };
- if (isCredentialPath(full)) return { ok: false, reason: "credential" };
- return { ok: true, path: full };
+ const relative = path.relative(parent, full);
+ if (relative === ".." || relative.startsWith(".." + path.sep) || path.isAbsolute(relative)) return { ok: false, reason: "escape" };
+ else {
+ const stat = await fs.lstat(full).catch(() => null);
+ if (!stat) return { ok: false, reason: "missing" };
+ if (stat.isSymbolicLink()) return { ok: false, reason: "symlink" };
+ if (!stat.isDirectory()) return { ok: false, reason: "not-directory" };
+ const uid = currentUid();
+ if (uid !== undefined && stat.uid !== uid) return { ok: false, reason: "uid" };
+ if (isCredentialPath(full)) return { ok: false, reason: "credential" };
+ return { ok: true, path: full };
+ }
}
/**
diff --git a/lib/host/project-flow-manifest.ts b/lib/host/project-flow-manifest.ts
index 4e43e882..45129b7d 100644
--- a/lib/host/project-flow-manifest.ts
+++ b/lib/host/project-flow-manifest.ts
@@ -8,15 +8,18 @@ import { parseFlow, object } from "@/lib/workflow/automation-schema";
import type { AutomationFlow } from "@/lib/contracts/automation";
export async function readProjectFlows(projectPath: string): Promise<{ flows: AutomationFlow[]; revision: string }> {
- const directory = path.join(projectPath, ".mso"), file = path.join(directory, "flows.json");
+ const approvedProject = await resolveReadable(projectPath);
+ if (approvedProject !== projectPath) throw new Error("project path must be canonical");
+ const directory = path.join(approvedProject, ".mso"), file = path.join(directory, "flows.json");
const stat = await fs.lstat(directory).catch((e: NodeJS.ErrnoException) => { if (e.code === "ENOENT") return null; throw e; });
if (!stat) return { flows: [], revision: "new" };
if (!stat.isDirectory() || stat.isSymbolicLink() || await fs.realpath(directory) !== directory) throw new Error("unsafe project flow directory");
const exists = await fs.lstat(file).catch((e: NodeJS.ErrnoException) => { if (e.code === "ENOENT") return null; throw e; });
if (!exists) return { flows: [], revision: "new" };
if (exists.isSymbolicLink()) throw new Error("unsafe project flow manifest");
- await resolveReadable(file);
- const raw = await readBoundedRegularFile(file, 64 * 1024);
+ const approvedFile = await resolveReadable(file);
+ if (approvedFile !== file) throw new Error("flow manifest path changed during read");
+ const raw = await readBoundedRegularFile(approvedFile, 64 * 1024);
if (raw === null) throw new Error("flow manifest unreadable or exceeds 64 KiB");
const parsed: unknown = JSON.parse(raw);
if (!object(parsed) || parsed.version !== 1 || Object.keys(parsed).some(k => !["version", "flows"].includes(k)) ||
@@ -26,7 +29,9 @@ export async function readProjectFlows(projectPath: string): Promise<{ flows: Au
return { flows, revision: sha256Text(raw) };
}
export async function manageProjectFlow(projectPath: string, input: { action: "upsert" | "delete"; id: string; flow?: unknown; revision: string }) {
- const directory = path.join(projectPath, ".mso"), file = path.join(directory, "flows.json");
+ const approvedProject = await resolveReadable(projectPath);
+ if (approvedProject !== projectPath) throw new Error("project path must be canonical");
+ const directory = path.join(approvedProject, ".mso"), file = path.join(directory, "flows.json");
await makeDir(directory);
return withSecurityStoreLock(file, async () => {
const current = await readProjectFlows(projectPath);
diff --git a/lib/workflow/automation-engine.ts b/lib/workflow/automation-engine.ts
index eb034e3e..819603e4 100644
--- a/lib/workflow/automation-engine.ts
+++ b/lib/workflow/automation-engine.ts
@@ -87,12 +87,13 @@ export async function startFlow(flow: AutomationFlow, project: string, raw: unkn
}));
}
export async function flowStatus(id: string, context: CapabilityRunContext, waitMs = 0) {
+ if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 25_000) throw new Error("wait_ms must be an integer from 0 to 25000");
const owner = flowOwner(principal(context));
let run = await readFlowRun(owner, id);
if (!run) throw new Error("flow run not found for this principal");
if (run.state === "running" && pending.has(id) && waitMs > 0) {
let timer: ReturnType<typeof setTimeout> | undefined;
- await Promise.race([pending.get(id), new Promise(resolve => { timer = setTimeout(resolve, Math.min(25_000, waitMs)); })]);
+ await Promise.race([pending.get(id), new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]);
clearTimeout(timer); run = await readFlowRun(owner, id) ?? run;
}
if (run.state === "running" && run.instance !== INSTANCE) {
diff --git a/lib/workflow/automation.test.ts b/lib/workflow/automation.test.ts
index 8f469608..d21ef8cb 100644
--- a/lib/workflow/automation.test.ts
+++ b/lib/workflow/automation.test.ts
@@ -43,6 +43,7 @@ describe("reusable project flows", () => {
expect(calls).toBe(1);
});
it("rejects missing inputs, raw shell, secret fields, prototype paths and insufficient grants", async () => {
+ for (const wait of [-1, 25001, NaN, Infinity]) await expect(flowStatus("0".repeat(32), context, wait)).rejects.toThrow("wait_ms");
expect(() => flowInputs(flow, {})).toThrow("missing input.name");
expect(() => flowInputs(flow, { name: "a", token: "secret" })).toThrow("secret_input");
expect(() => parseFlow({ ...flow, steps: [{ id: "bad", tool: "exec_run", arguments: { command: "echo x" } }] })).toThrow("invalid");
diff --git a/scripts/cli/flows.sh b/scripts/cli/flows.sh
index 3b4154c5..e4e19b43 100644
--- a/scripts/cli/flows.sh
+++ b/scripts/cli/flows.sh
@@ -3,7 +3,9 @@
run_flow() {
local sub="${1:-list}" id="" project="$PWD" input='{}' key="" wait=0 revision="" body result
shift || true
- case "$sub" in inspect|run|status|save|delete) id="${1:?flow/run id required}"; shift ;; esac
+ case "$sub" in
+ inspect|run|status|save|delete) id="${1:?flow/run id required}"; shift ;;
+ esac
while [ $# -gt 0 ]; do
case "$1" in
--project) project="${2:?project required}"; shift 2 ;;
@@ -14,7 +16,9 @@ run_flow() {
*) die "unknown flow option: $1" ;;
esac
done
- case "$input" in @*) input=$(cat -- "${input#@}") ;; esac
+ case "$input" in
+ @*) input=$(cat -- "${input#@}") ;;
+ esac
case "$sub" in
list|inspect) jget "/api/v1/flows?project=$(enc "$project")&flow=$(enc "$id")"; return ;;
status) result=$(jget "/api/v1/flows?run_id=$(enc "$id")&wait_ms=$((wait * 25000))") ;;
@@ -27,11 +31,13 @@ run_flow() {
local action=upsert; [ "$sub" = delete ] && action=delete
body=$(jq -n --arg action "$action" --arg project "$project" --arg flow "$id" --arg revision "$revision" --argjson definition "$input" '{action:$action,project:$project,flow:$flow,revision:$revision,definition:$definition}')
jpost "/api/v1/flows" "$body"; return ;;
- *) die "usage: mso $U_flow" ;;
+ *) die "usage: mso ${U_flow:-flow}" ;;
esac
while [ "$wait" -eq 1 ] && [ "$(jq -r .state <<<"$result")" = running ]; do
result=$(jget "/api/v1/flows?run_id=$(enc "$id")&wait_ms=25000")
done
printf '%s\n' "$result"
- case "$(jq -r .state <<<"$result")" in failed|interrupted) return 1 ;; esac
+ case "$(jq -r .state <<<"$result")" in
+ failed|interrupted) return 1 ;;
+ esac
}
diff --git a/scripts/e2e/automation.mjs b/scripts/e2e/automation.mjs
index 56324261..d55321cd 100644
--- a/scripts/e2e/automation.mjs
+++ b/scripts/e2e/automation.mjs
@@ -4,6 +4,7 @@ import path from "node:path";
import { expect } from "@playwright/test";
export async function automationJourney(page, fixture) {
+ await page.setViewportSize({width:1280,height:900});
await fixture.seedMcp("exec");
const meta = {"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}};
const rpc = async (method, params = {}) => {