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.

test(security): verify production sockets and preserve bounded project scans

rahmanef1c55bdd39ae0
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 4dea3438..06891524 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -35,6 +35,7 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh
**Tests**
+- `security` verify production sockets and preserve bounded project scans
- `lock` wait for the privacy curtain keyboard listener before unlocking
## 2026-10-07
diff --git a/lib/host/path-credentials.ts b/lib/host/path-credentials.ts
index f72a594f..231373d7 100644
--- a/lib/host/path-credentials.ts
+++ b/lib/host/path-credentials.ts
@@ -87,11 +87,16 @@ export function isAppSecret(real: string): boolean {
/** Exported for the project/skill enumerators: they walk directory TREES the
* per-path resolvers never see, and must drop a credential directory themselves
* rather than discover it one `resolveReadable` too late. */
-export function isCredentialPath(real: string): boolean {
- const store = path.join(homeDir(), ".mso");
- if (real === store || isUnderRoot(real, store)) return true;
- try { if (isUnderRoot(real, realpathSync.native(store))) return true; } catch { /* No store yet. */ }
- if (isSensitivePath(real)) return true;
+export function credentialRoots(): string[] {
+ const names = process.env.OS_FS_ALLOW_SENSITIVE === "1" ? [".mso"] : [".mso", ...SENSITIVE_HOME];
+ return names.flatMap((name) => {
+ const lexical = path.join(homeDir(), name);
+ try { return [lexical, realpathSync.native(lexical)]; } catch { return [lexical]; }
+ });
+}
+
+export function isCredentialPath(real: string, roots = credentialRoots()): boolean {
+ if (roots.some((root) => isUnderRoot(real, root))) return true;
const names = path.resolve(real).split(path.sep);
if (names.some((name) => name.startsWith(".env") && name !== ".env.example")) return true;
const base = path.basename(real);
diff --git a/lib/host/project-candidate.ts b/lib/host/project-candidate.ts
index 026a74da..f1f160d6 100644
--- a/lib/host/project-candidate.ts
+++ b/lib/host/project-candidate.ts
@@ -26,7 +26,7 @@ const currentUid = (): number | undefined => (typeof process.getuid === "functio
/** A single path component: real, visible, not a link, owned by us. `parent` is already
* validated (or is the container), so this never re-walks the whole prefix. */
-async function validateComponent(parent: string, name: string): Promise<CandidateResult> {
+async function validateComponent(parent: string, name: string, credentialPaths?: string[]): Promise<CandidateResult> {
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);
@@ -39,7 +39,7 @@ async function validateComponent(parent: string, name: string): Promise<Candidat
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" };
+ if (isCredentialPath(full, credentialPaths)) return { ok: false, reason: "credential" };
return { ok: true, path: full };
}
}
@@ -48,8 +48,8 @@ async function validateComponent(parent: string, name: string): Promise<Candidat
* ONE direct child of a container — the enumeration case and the exact-name/alias probe.
* A final realpath check catches a swap between lstat and here.
*/
-export async function validateProjectChild(container: ProjectContainer, name: string): Promise<CandidateResult> {
- const component = await validateComponent(container.path, name);
+export async function validateProjectChild(container: ProjectContainer, name: string, credentialPaths?: string[]): Promise<CandidateResult> {
+ const component = await validateComponent(container.path, name, credentialPaths);
if (!component.ok) return component;
const real = await fs.realpath(/* turbopackIgnore: true */ component.path).catch(() => null);
if (real !== component.path || !isUnderRoot(real, container.path)) return { ok: false, reason: "escape" };
diff --git a/lib/host/project-roots.ts b/lib/host/project-roots.ts
index d5394545..7fc9bf3d 100644
--- a/lib/host/project-roots.ts
+++ b/lib/host/project-roots.ts
@@ -18,6 +18,7 @@
// could never advance: every call rebuilt the same capped prefix.
import { promises as fs } from "fs";
import path from "path";
+import { credentialRoots } from "./path-credentials";
import { validateProjectChild } from "./project-candidate";
import { encodeCursor } from "./project-cursor";
import {
@@ -52,6 +53,8 @@ async function walkContainer(
deadlineAt: number,
budget: number,
): Promise<Walk> {
+ // One bounded metadata walk shares its alias snapshot; actual file reads revalidate paths.
+ const protectedPaths = credentialRoots();
const dirs: string[] = [];
let consumed = skipEntries;
let seen = 0;
@@ -76,7 +79,7 @@ async function walkContainer(
if (containerPaths.has(full)) skipped += 1;
else if (!entry.isDirectory() || entry.name.startsWith(".")) skipped += 1;
else {
- const candidate = await validateProjectChild(container, entry.name);
+ const candidate = await validateProjectChild(container, entry.name, protectedPaths);
if (candidate.ok) dirs.push(candidate.path);
else skipped += 1;
}
diff --git a/scripts/e2e/release.mjs b/scripts/e2e/release.mjs
index 946063e3..695f118f 100644
--- a/scripts/e2e/release.mjs
+++ b/scripts/e2e/release.mjs
@@ -14,6 +14,7 @@ import { memoryBackupHistoryJourney } from "./memory-backup-history.mjs";
import { aiProviderSwitchJourney } from "./ai-provider-switch.mjs";
import { shellNoticesJourney } from "./shell-notices.mjs";
+execFileSync(process.execPath, ["scripts/e2e/socket-authority.mjs"], { stdio: "inherit", timeout: 30000 });
execFileSync(process.execPath, ["scripts/e2e/shell-apps.mjs"], { stdio: "inherit" });
execFileSync(process.execPath, ["scripts/e2e/mcp-page.mjs"], { stdio: "inherit" });
execFileSync(process.execPath, ["scripts/e2e/workflow-embeds.mjs"], { stdio: "inherit" });
diff --git a/scripts/e2e/socket-authority.mjs b/scripts/e2e/socket-authority.mjs
new file mode 100644
index 00000000..b606239d
--- /dev/null
+++ b/scripts/e2e/socket-authority.mjs
@@ -0,0 +1,51 @@
+import assert from "node:assert/strict";
+import { createServer } from "node:http";
+import { connect } from "node:net";
+import { once } from "node:events";
+import { releaseFixture } from "./release-fixture.mjs";
+
+const sockets = new Set();
+const upstream = createServer();
+let remote;
+upstream.on("upgrade", (request, socket) => {
+ assert.equal(request.headers.cookie, undefined);
+ assert.equal(request.headers.authorization, undefined);
+ remote = socket; sockets.add(socket);
+ socket.write("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n");
+ socket.on("data", (chunk) => socket.write(chunk));
+});
+await new Promise((resolve) => upstream.listen(0, "127.0.0.1", resolve));
+const previous = process.env.HERMES_DASHBOARD_URL;
+process.env.HERMES_DASHBOARD_URL = `http://127.0.0.1:${upstream.address().port}`;
+let fixture;
+try {
+ fixture = await releaseFixture();
+ const response = await fetch(fixture.base + "/api/auth/login", { method: "POST", headers: { "content-type": "application/json", origin: fixture.base }, body: JSON.stringify({ password: fixture.password, deviceId: fixture.device }) });
+ assert.equal(response.status, 200);
+ const cookie = response.headers.get("set-cookie").split(";")[0];
+ assert.equal((await fetch(fixture.base + "/api/internal/socket-policy", { method: "POST" })).status, 404);
+ async function open() {
+ const client = connect(Number(new URL(fixture.base).port), "127.0.0.1"); sockets.add(client);
+ client.on("error", () => {});
+ const first = Promise.race([once(client, "data").then(([data]) => data.toString()), once(client, "close").then(() => "")]);
+ client.write(`GET /socket HTTP/1.1\r\nHost: hermes.mso.example.com\r\nOrigin: http://hermes.mso.example.com\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nCookie: ${cookie}\r\nAuthorization: must-not-forward\r\n\r\n`);
+ return { client, handshake: await first };
+ }
+ const { client, handshake } = await open(); assert.match(handshake, /101 Switching Protocols/);
+ const echo = once(client, "data"); client.write("permitted"); assert.equal((await echo)[0].toString(), "permitted");
+ let delivered = ""; client.on("data", (chunk) => { delivered += chunk.toString(); });
+ const closed = once(client, "close"); await fixture.setRole("viewer"); remote.write("private-after-demotion"); await closed;
+ assert.equal(delivered, "");
+ await fixture.setRole("owner");
+ const idle = await open(); assert.match(idle.handshake, /101 Switching Protocols/);
+ const idleClosed = once(idle.client, "close");
+ assert.equal((await fetch(fixture.base + "/api/auth/logout", { method: "POST", headers: { cookie, origin: fixture.base } })).status, 200);
+ await idleClosed;
+ assert.doesNotMatch((await open()).handshake, /101/);
+ console.log("PASS production socket authority: real login/policy RPC, cookie stripping, live demotion, idle logout and replay refusal");
+} finally {
+ for (const socket of sockets) socket.destroy();
+ await fixture?.close();
+ await new Promise((resolve) => upstream.close(resolve));
+ if (previous === undefined) delete process.env.HERMES_DASHBOARD_URL; else process.env.HERMES_DASHBOARD_URL = previous;
+}