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(review): preserve session and surface store invariants

Rahman6d5cace73144
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 03863fd6..eb745385 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -13,6 +13,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `review` preserve session and surface store invariants
- `auth` permanently revoke retired cookie sessions
- `workflows` preserve explicit empty sandbox
- `auth` bind sessions to cookie scope
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index bc85ed76..1c7461c5 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -1,3 +1,16 @@
+## 2026-09-18 — Close external-editor review around durable session policy and owner stores
+
+The latest PR review found four boundary issues after the cookie-policy epoch landed. CLI device
+approve/role/revoke writes now preserve the durable `sessionPolicy` record instead of rewriting
+the auth store without it. Repeated session validation uses a read-only fast path when the stored
+scope already matches and acquires the cross-process mutation lock only for an actual rotation,
+with a locked recheck before writing. Workflow-only surface updates preserve MCP Page placement
+only from an existing row that itself normalizes as a valid reviewed app, so malformed legacy
+bytes cannot create Page approval. `MSO_SURFACE_APPS_FILE` is now one of the explicitly allowed
+owner security-store paths, so a configured registry outside the home directory remains writable
+without a duplicate filesystem-write-root declaration. Existing validated Page auth query metadata
+is preserved unchanged. Targeted regressions cover all four boundaries.
+
## 2026-09-18 — Permanently revoke prior cookie-policy generations
A follow-up security review found that a deterministic scope label could revive an old signed session if configuration later returned to the same cookie Domain. The private auth-device store now keeps one durable cookie-policy epoch and rotates it on every actual scope transition, including A to host-only to A. Signed browser sessions carry both scope and epoch; route and middleware/WebSocket authorization require both. Existing approved devices and roles are preserved, but pre-epoch sessions require a one-time sign-in. Workflow edits also preserve an existing reviewed MCP Page auth path with query parameters without allowing the Workflow endpoint to create or change that Page-owned metadata.
diff --git a/lib/auth/device-store.test.ts b/lib/auth/device-store.test.ts
index 5c7f87b4..196d3be8 100644
--- a/lib/auth/device-store.test.ts
+++ b/lib/auth/device-store.test.ts
@@ -110,6 +110,13 @@ describe("device-store — an unreadable file must never look like an empty one"
expect((await listDevices()).sessionPolicy).toEqual(returned);
});
+ it("reads an unchanged session policy without taking the mutation lock", async () => {
+ const { currentSessionPolicy } = await load();
+ const first = await currentSessionPolicy("host");
+ await fs.writeFile(`${store}.lock.recovery`, `${process.pid}:fixture`, { mode: 0o600 });
+ await expect(currentSessionPolicy("host")).resolves.toEqual(first);
+ });
+
it("writes the store 0600 inside a 0700 dir", async () => {
const { approveDevice } = await load();
await approveDevice(DEV, "my laptop");
diff --git a/lib/auth/device-store.ts b/lib/auth/device-store.ts
index 95e34118..9c77eb2c 100644
--- a/lib/auth/device-store.ts
+++ b/lib/auth/device-store.ts
@@ -153,9 +153,14 @@ function ownerCount(store: DeviceStore): number {
* transition rotates the epoch, so A → host → A can never revive a token minted
* during the earlier A generation even if the browser retained that cookie.
*/
-export function currentSessionPolicy(scope: string): Promise<SessionPolicy> {
- if (!COOKIE_SCOPE_RE.test(scope)) return Promise.reject(new Error("invalid_session_cookie_scope"));
+export async function currentSessionPolicy(scope: string): Promise<SessionPolicy> {
+ if (!COOKIE_SCOPE_RE.test(scope)) throw new Error("invalid_session_cookie_scope");
+ // Session validation is read-heavy. Avoid taking the cross-process mutation
+ // lock when the durable policy already matches this process configuration.
+ const current = await read();
+ if (current.sessionPolicy?.scope === scope) return current.sessionPolicy;
return mutate(async () => {
+ // Recheck under the lock so only one contender rotates a scope transition.
const store = await read();
if (store.sessionPolicy?.scope === scope) return store.sessionPolicy;
const sessionPolicy = { scope, epoch: randomUUID(), changedAt: Date.now() };
diff --git a/lib/security-store-path.test.ts b/lib/security-store-path.test.ts
index 2ea436f1..9a80fd98 100644
--- a/lib/security-store-path.test.ts
+++ b/lib/security-store-path.test.ts
@@ -1,13 +1,16 @@
import { constants, promises as fs } from "node:fs";
import os from "node:os";
import path from "node:path";
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { pinSecurityStorePath } from "./security-store-path";
import { withSecurityStoreLock } from "./security-store-lock";
const roots: string[] = [];
async function fixture() { const root = await fs.mkdtemp(path.join(os.tmpdir(), "mso-pinned-store-")); roots.push(root); return root; }
-afterEach(async () => { for (const root of roots.splice(0)) await fs.rm(root, { recursive: true, force: true }); });
+afterEach(async () => {
+ vi.unstubAllEnvs();
+ for (const root of roots.splice(0)) await fs.rm(root, { recursive: true, force: true });
+});
describe("pinned owner security-store paths", () => {
it("supports the existing hidden artifact-lock basename", async () => {
@@ -27,6 +30,15 @@ describe("pinned owner security-store paths", () => {
const root = await fixture(); await fs.chmod(root, 0o777);
await expect(pinSecurityStorePath(path.join(root, "store.json"))).rejects.toThrow(/not writable by others/);
});
+ it("authorizes the configured owner surface registry without another write-root entry", async () => {
+ const root = await fixture(), file = path.join(root, "surface-apps.json");
+ vi.stubEnv("VITEST", "");
+ vi.stubEnv("MSO_SURFACE_APPS_FILE", file);
+ const pinned = await pinSecurityStorePath(file);
+ try { expect(pinned.absolute).toBe(file); }
+ finally { await pinned.directory.close(); }
+ });
+
it("keeps operations on the pinned inode after the pathname is replaced", async () => {
const root = await fixture(), original = path.join(root, "original"), moved = path.join(root, "moved");
await fs.mkdir(original, { mode: 0o700 });
diff --git a/lib/security-store-path.ts b/lib/security-store-path.ts
index 35da79a5..c3735daa 100644
--- a/lib/security-store-path.ts
+++ b/lib/security-store-path.ts
@@ -10,7 +10,7 @@ const STORE_ENV = [
"OS_DEVICE_STORE", "OS_MCP_STORE", "OS_INFRA_STORE", "OS_MEMORY_STORE", "OS_MCP_ACTIVITY_LOG",
"OS_A2A_STORE", "OS_A2A_TASK_STORE", "OS_A2A_CREDENTIAL_STORE", "OS_A2A_INBOUND_TOKEN_STORE",
"OS_A2A_LOCAL_AUTH_STORE", "OS_LOCAL_AGENT_MESSAGE_STORE", "OS_LOCAL_AGENT_PRESENCE_STORE",
- "OS_CONFIG_STORE", "OS_PREFS_PATH", "OS_SKILL_MEMORY_STORE",
+ "OS_CONFIG_STORE", "OS_PREFS_PATH", "OS_SKILL_MEMORY_STORE", "MSO_SURFACE_APPS_FILE",
] as const;
const DIRECTORY_ENV = ["OS_TOOL_FORGE_DIR", "OS_AGENT_MEMORY_DIR", "OS_AGENT_SESSIONS_DIR", "OS_PROJECT_AGENT_TASKS_DIR"] as const;
const expand = (value: string) => path.resolve(expandOwnerStorePath(value));
diff --git a/lib/surfaces/manage.test.ts b/lib/surfaces/manage.test.ts
index fdf62fb0..59e1799b 100644
--- a/lib/surfaces/manage.test.ts
+++ b/lib/surfaces/manage.test.ts
@@ -40,6 +40,14 @@ describe("owner-reviewed workflow surface configuration", () => {
expect(saved.externalAuthPath).toBe(pageAuth);
await expect(save({ ...app, externalAuthPath: "/?auth=other" })).rejects.toThrow("workflow_login_path_must_not_contain_query");
});
+ it("does not inherit legacy Page approval from an invalid existing row", async () => {
+ await fs.writeFile(file, JSON.stringify([{ ...app, title: "", placements: undefined }]));
+ await save({ ...app, title: "Recovered workflow editor" });
+ const saved = (await surfaceRegistrySnapshot()).apps[0];
+ expect(saved.title).toBe("Recovered workflow editor");
+ expect(saved.placements).toEqual(["workflows"]);
+ });
+
it("never adds Page approval to new or workflow-only entries", async () => {
await save();
expect((await surfaceRegistrySnapshot()).apps[0].placements).toEqual(["workflows"]);
diff --git a/lib/surfaces/manage.ts b/lib/surfaces/manage.ts
index aed07426..0d2ece9a 100644
--- a/lib/surfaces/manage.ts
+++ b/lib/surfaces/manage.ts
@@ -47,12 +47,12 @@ export async function saveWorkflowSurface(input: Record<string, unknown>) {
const matches = entries.filter((entry) => entry.id === selected.id);
if (matches.length > 1) throw new SurfaceConfigError("duplicate_surface_identity", 409);
const replacement = { ...selected };
- // Missing placements is legacy Page approval; this workflow-only operation
- // may preserve that grant but cannot create or mutate Page-only auth metadata.
+ // Missing placements is legacy Page approval only when the existing row is
+ // itself a valid reviewed app. Invalid historical bytes cannot grant Page.
const existing = matches[0];
- const sharesPage = Boolean(existing && (existing.placements === undefined ||
- (Array.isArray(existing.placements) && existing.placements.includes("mcp-page"))));
const existingNormalized = existing ? (await configuredSurfaceApps(JSON.stringify([existing])))[0] : undefined;
+ const sharesPage = Boolean(existingNormalized && (existingNormalized.placements === undefined ||
+ existingNormalized.placements?.includes("mcp-page")));
if (selected.externalAuthPath?.includes("?") && (!sharesPage ||
selected.externalAuthPath !== existingNormalized?.externalAuthPath)) {
throw new SurfaceConfigError("workflow_login_path_must_not_contain_query");
diff --git a/scripts/approve-device-lock.test.ts b/scripts/approve-device-lock.test.ts
index 8bf5f289..86b95ff7 100644
--- a/scripts/approve-device-lock.test.ts
+++ b/scripts/approve-device-lock.test.ts
@@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process";
-import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
@@ -18,6 +18,32 @@ describe("approve-device cross-process lock protocol", () => {
expect(source).not.toContain("function recoverAbandonedLock");
});
+ it("preserves the durable session epoch across CLI approve, role and revoke writes", () => {
+ const root = mkdtempSync(path.join(os.tmpdir(), "mso-approve-policy-"));
+ const store = path.join(root, "devices.json");
+ const owner = "a".repeat(32), device = "b".repeat(32);
+ const policy = { scope: "host", epoch: "epoch-1234567890abcdef", changedAt: 1 };
+ writeFileSync(store, JSON.stringify({
+ approved: { [owner]: { label: "owner", approvedAt: 1, role: "owner" } },
+ pending: { [device]: { label: "phone", firstSeen: 1, lastSeen: 1, ip: "127.0.0.1", attempts: 1 } },
+ sessionPolicy: policy,
+ }));
+ const run = (args: string[]) => spawnSync(process.execPath, [SCRIPT, ...args], {
+ env: { ...process.env, OS_DEVICE_STORE: store, MSO_SYSTEMCTL_BIN: "/bin/true" }, encoding: "utf8",
+ });
+ const savedPolicy = () => JSON.parse(readFileSync(store, "utf8")).sessionPolicy;
+ try {
+ expect(run([device, "phone", "--role", "viewer"]).status).toBe(0);
+ expect(savedPolicy()).toEqual(policy);
+ expect(run(["--set-role", device, "operator"]).status).toBe(0);
+ expect(savedPolicy()).toEqual(policy);
+ expect(run(["--revoke", device]).status).toBe(0);
+ expect(savedPolicy()).toEqual(policy);
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+ });
+
it("refuses approval as a role-change bypass for an existing device", () => {
const root = mkdtempSync(path.join(os.tmpdir(), "mso-approve-role-"));
const store = path.join(root, "devices.json");
diff --git a/scripts/approve-device.js b/scripts/approve-device.js
index 32c28e54..ee03e5ce 100755
--- a/scripts/approve-device.js
+++ b/scripts/approve-device.js
@@ -20,7 +20,13 @@ function read() {
try {
const p = JSON.parse(fs.readFileSync(STORE, "utf8"));
const approved = normalizeApproved(p.approved);
- return { approved, pending: p.pending || {} };
+ return {
+ approved,
+ pending: p.pending || {},
+ ...(p.sessionPolicy && typeof p.sessionPolicy === "object" && !Array.isArray(p.sessionPolicy)
+ ? { sessionPolicy: p.sessionPolicy }
+ : {}),
+ };
} catch (error) {
if (error && error.code === "ENOENT") return { approved: {}, pending: {} };
throw error;