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(security): bind Convex snapshot path identity

Rahman658f2af380eb
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index aa845a43..75a50b97 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -12,6 +12,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `security` bind Convex snapshot path identity
- `security` pin Convex snapshot import bytes
- `security` keep macOS installer fully parseable
- `mcp` keep architecture ratchet and bootstrap tests green
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index b449e6ed..225aff51 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -1,3 +1,14 @@
+## 2026-09-19 — Bind Convex snapshot authorization to the opened descriptor
+
+The prior staging hardening consumed bytes through one open descriptor but still authorized the
+caller path before opening it. `O_NOFOLLOW` protects only the final component, so a parent-path
+rename/symlink swap could otherwise redirect the later open outside the reviewed read root. Snapshot
+staging now re-runs `resolveReadable()` immediately after open, requires the caller-visible canonical
+path to be unchanged, and compares the named file's `dev`/`ino` to the descriptor `fstat`. The same
+identity check runs again after the private descriptor-only copy. An adversarial regression replaces
+the path after `open()` and proves the import is rejected rather than staging the old descriptor bytes
+under a now-different pathname.
+
## 2026-09-19 — Pin Convex snapshot imports to validated bytes
The security inventory exposed CodeQL alert #139: snapshot metadata was checked by
diff --git a/lib/infra/convex-cloud-cli-runner.ts b/lib/infra/convex-cloud-cli-runner.ts
index 31918e4b..e0c3fe98 100644
--- a/lib/infra/convex-cloud-cli-runner.ts
+++ b/lib/infra/convex-cloud-cli-runner.ts
@@ -107,12 +107,13 @@ export async function convexProjectContext(projectPath: unknown) {
export async function convexSnapshotContext(snapshotPath: unknown) {
if (typeof snapshotPath !== "string" || !snapshotPath.trim())
throw new IntegrationError("invalid_snapshot_path");
- const snapshot = await resolveReadable(snapshotPath.trim()).catch(() => {
+ const requestedPath = snapshotPath.trim();
+ const snapshot = await resolveReadable(requestedPath).catch(() => {
throw new IntegrationError("invalid_snapshot_path");
});
if (!snapshot.toLowerCase().endsWith(".zip"))
throw new IntegrationError("convex_snapshot_zip_required");
- return { snapshot, ...(await stageConvexSnapshot(snapshot)) };
+ return { snapshot, ...(await stageConvexSnapshot(requestedPath, snapshot)) };
}
export function convexCliEnv(deployKey: string): Record<string, string> {
diff --git a/lib/infra/convex-cloud-snapshot-security.test.ts b/lib/infra/convex-cloud-snapshot-security.test.ts
index c5b5ec06..3e388cb9 100644
--- a/lib/infra/convex-cloud-snapshot-security.test.ts
+++ b/lib/infra/convex-cloud-snapshot-security.test.ts
@@ -43,3 +43,36 @@ it("stages the checked snapshot from one open descriptor into a private immutabl
await context.cleanup();
await expect(fs.stat(context.stagedSnapshot)).rejects.toMatchObject({ code: "ENOENT" });
});
+
+it("rejects a snapshot path replaced after the descriptor is opened", async () => {
+ const replacement = path.join(root, "replacement.zip");
+ await fs.writeFile(
+ replacement,
+ Buffer.from([
+ 0x50, 0x4b, 0x05, 0x06, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ ]),
+ { mode: 0o600 },
+ );
+ const openedOriginal = path.join(root, "opened-original.zip");
+ const realOpen = fs.open.bind(fs);
+ let swapped = false;
+ const openSpy = vi.spyOn(fs, "open").mockImplementation(async (...args) => {
+ const handle = await realOpen(...args);
+ if (!swapped && String(args[0]) === snapshot) {
+ swapped = true;
+ await fs.rename(snapshot, openedOriginal);
+ await fs.rename(replacement, snapshot);
+ }
+ return handle;
+ });
+ try {
+ const { convexSnapshotContext } = await import("./convex-cloud-cli-runner");
+ await expect(convexSnapshotContext(snapshot)).rejects.toMatchObject({
+ code: "invalid_snapshot_path",
+ });
+ expect(swapped).toBe(true);
+ } finally {
+ openSpy.mockRestore();
+ }
+});
diff --git a/lib/infra/convex-snapshot-stage.ts b/lib/infra/convex-snapshot-stage.ts
index 737faaa6..4272e0c5 100644
--- a/lib/infra/convex-snapshot-stage.ts
+++ b/lib/infra/convex-snapshot-stage.ts
@@ -2,12 +2,27 @@ import { createHash } from "node:crypto";
import { constants as fsConstants, promises as fs } from "node:fs";
import os from "node:os";
import path from "node:path";
+import { resolveReadable } from "@/lib/host/paths";
import { IntegrationError } from "./identity";
const MAX_SNAPSHOT_BYTES = 2 * 1024 * 1024 * 1024;
const COPY_CHUNK_BYTES = 1024 * 1024;
-export async function stageConvexSnapshot(snapshot: string) {
+async function assertOpenedSnapshotIdentity(
+ requestedPath: string,
+ canonicalSnapshot: string,
+ opened: Awaited<ReturnType<typeof fs.stat>>,
+) {
+ const current = await resolveReadable(requestedPath).catch(() => {
+ throw new IntegrationError("invalid_snapshot_path");
+ });
+ if (current !== canonicalSnapshot) throw new IntegrationError("invalid_snapshot_path");
+ const named = await fs.lstat(canonicalSnapshot).catch(() => null);
+ if (!named?.isFile() || named.dev !== opened.dev || named.ino !== opened.ino)
+ throw new IntegrationError("invalid_snapshot_path");
+}
+
+export async function stageConvexSnapshot(requestedPath: string, snapshot: string) {
const handle = await fs
.open(snapshot, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW)
.catch(() => {
@@ -21,6 +36,11 @@ export async function stageConvexSnapshot(snapshot: string) {
if (typeof process.getuid === "function" && stat.uid !== process.getuid())
throw new IntegrationError("invalid_snapshot_path");
+ // Re-authorize the caller path after open and bind its current name to the
+ // already-open descriptor. O_NOFOLLOW protects only the final component; this
+ // additionally rejects parent-directory/symlink swaps between check and open.
+ await assertOpenedSnapshotIdentity(requestedPath, snapshot, stat);
+
const head = Buffer.alloc(4);
const first = await handle.read(head, 0, 4, 0);
if (
@@ -79,6 +99,10 @@ export async function stageConvexSnapshot(snapshot: string) {
after.ctimeMs !== stat.ctimeMs
)
throw new IntegrationError("invalid_snapshot_path");
+ // Bind the final result metadata to the same caller-visible path as well.
+ // A late rename/replacement after the copy is rejected instead of returning
+ // a staged snapshot whose audit path now names different bytes.
+ await assertOpenedSnapshotIdentity(requestedPath, snapshot, stat);
return {
stagedSnapshot,