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: close domain integration regressions and preserve strict gates

Abdurrahman Fakhrul1f33c9afb551
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index eb3eadd7..970f78bf 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -12,6 +12,10 @@ Integration preserves the current upstream session-turn runner, provider usage a
PR verification also exposed a sourced CLI usage variable without its module-level fallback and four test-only inline import types that the pinned Semgrep parser could not read. The CLI now follows neighboring modules' explicit fallback, and named type aliases preserve the exact mocks and assertions. Actual ShellCheck 0.11.0 and a complete Semgrep 1.174.0 strict scan pass after these repairs; no scanner rules or exclusions were relaxed.
+The subsequent managed-domain merge exposed additional integration gates: operator-specific handoff paths, an unchecked CLI directory change, and test/Bash syntax that the pinned parser could not read. The paths are portable, domain dispatch stops when its checkout cannot be entered, and equivalent type aliases and multiline case arms preserve behavior. The heartbeat fixture now includes the extracted named-config helper. Interrupted connector recovery accepts the two exact failure phases of its immediate-exit fixture while retaining state, liveness and retry checks, and also verifies the pending receipt is unchanged.
+
+CodeQL also identified a production pathname reread in the new named-gateway helper. Its final comparison now reuses the initial no-follow, nonblocking descriptor reader, checks device/inode/mode before reading bytes, and preserves content comparison plus the existing durable replacement. Deterministic regressions cover a symlink swap after open and rejection of a different inode before reading. Gateway locks still coordinate MSO writers rather than provide atomic compare-and-swap with external editors. The separate custom domain-store filesystem-exclusion limitation remains recorded in the PR.
+
## 2026-10-18: Freeze the complete Nakama target and separate inventory from runtime proof
The approved v0.1 draft spans 64 requirement groups, 24 packages, eight stages and 30 acceptance journeys. The immutable snapshot preserves all original contracts and variants; the generated current reference reads a separate implementation map so progress cannot silently reduce the target. Source receipts identify all 100 distinct referenced files at the pinned Nakama and MSO commits. File identity proves source availability, not runtime behavior.
diff --git a/lib/infra/managed-domain.test.ts b/lib/infra/managed-domain.test.ts
index e82eec70..b75d9090 100644
--- a/lib/infra/managed-domain.test.ts
+++ b/lib/infra/managed-domain.test.ts
@@ -5,8 +5,10 @@ import { readInfraProvider } from "./store";
import { ensureManagedDomainGateway, inspectManagedDomainGateway } from "./managed-domain-gateway";
import { ensureManagedDomainDns, ensureManagedDomainRoute, inspectManagedDomainRoute } from "./managed-domain";
+type HttpModule = typeof import("./http");
+
vi.mock("./store", () => ({ readInfraProvider: vi.fn() }));
-vi.mock("./http", async importOriginal => ({ ...await importOriginal<typeof import("./http")>(), request: vi.fn() }));
+vi.mock("./http", async importOriginal => ({ ...await importOriginal<HttpModule>(), request: vi.fn() }));
vi.mock("./managed-domain-gateway", () => ({ ensureManagedDomainGateway: vi.fn(), inspectManagedDomainGateway: vi.fn() }));
const input: ManagedDomainRoute = {
diff --git a/scripts/cli/domains.sh b/scripts/cli/domains.sh
index bbe67e22..266b090e 100644
--- a/scripts/cli/domains.sh
+++ b/scripts/cli/domains.sh
@@ -7,6 +7,6 @@ run_domains() {
local domain_env domain_local
domain_env="$(realpath -m -- "$ENVF")"
domain_local="$(gateway_local_url)"
- (cd "$ROOT"; MSO_DOMAIN_ENV="$domain_env" MSO_DOMAIN_LOCAL_ORIGIN="$domain_local" \
+ (cd "$ROOT" || exit; MSO_DOMAIN_ENV="$domain_env" MSO_DOMAIN_LOCAL_ORIGIN="$domain_local" \
bun --no-env-file --conditions=react-server "$ROOT/scripts/mso-domain.ts" "$@")
}
diff --git a/scripts/cli/managed-apps.sh b/scripts/cli/managed-apps.sh
index af721652..954b75af 100644
--- a/scripts/cli/managed-apps.sh
+++ b/scripts/cli/managed-apps.sh
@@ -19,7 +19,10 @@ mso_mapp_lifecycle() {
mso_mapp_enable() {
local id="${1:?application ID required}" response job
shift
- case "$id" in hermes|openclaw|9router) ;; *) die "choose hermes, openclaw or 9router" ;; esac
+ case "$id" in
+ hermes|openclaw|9router) ;;
+ *) die "choose hermes, openclaw or 9router" ;;
+ esac
response="$(jget "/api/v1/managed-apps/$(enc "$id")")"
if ! jq -e '.app.installed == true' <<<"$response" >/dev/null; then
response="$(jpost "/api/v1/managed-apps/$(enc "$id")/install" "$(kv_args "$@")")"
diff --git a/scripts/lib/gateway-named-config.mjs b/scripts/lib/gateway-named-config.mjs
index 8c2b8629..2338cbca 100644
--- a/scripts/lib/gateway-named-config.mjs
+++ b/scripts/lib/gateway-named-config.mjs
@@ -19,16 +19,21 @@ function appHosts(template) {
if (!hosts.every(hostname)) reject('invalid managed app host template');
return hosts;
}
-function readConfig(root, file) {
- const YAML = loadModule(path.join(root, 'node_modules/yaml'));
+function readConfigFile(file, expected) {
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
let stat, text;
try {
stat = fs.fstatSync(fd);
if (!stat.isFile() || stat.uid !== process.getuid() || (stat.mode & 0o022)) reject('unsafe named tunnel config');
if (stat.size > 1024 * 1024) reject('named tunnel config is too large');
+ if (expected && (stat.dev !== expected.dev || stat.ino !== expected.ino || stat.mode !== expected.mode)) reject('named tunnel config changed concurrently');
text = fs.readFileSync(fd, 'utf8');
} finally { fs.closeSync(fd); }
+ return { text, stat };
+}
+function readConfig(root, file) {
+ const YAML = loadModule(path.join(root, 'node_modules/yaml'));
+ const { text, stat } = readConfigFile(file);
const doc = YAML.parseDocument(text, { uniqueKeys: true });
if (doc.errors.length) reject('invalid named tunnel YAML');
const cfg = doc.toJS({ maxAliasCount: 10 });
@@ -72,9 +77,8 @@ function validateConfig(cfg, file, publicOrigin, localOrigin, template, exact =
if (!st.isFile() || st.isSymbolicLink() || st.uid !== process.getuid() || (st.mode & 0o077)) reject('credentials-file must be private and owner-owned');
}
function atomicReplace(file, snapshot, text) {
- const current = fs.lstatSync(file);
- if (!current.isFile() || current.isSymbolicLink() || current.dev !== snapshot.stat.dev || current.ino !== snapshot.stat.ino ||
- current.mode !== snapshot.stat.mode || fs.readFileSync(file, 'utf8') !== snapshot.text) reject('named tunnel config changed concurrently');
+ const current = readConfigFile(file, snapshot.stat);
+ if (current.text !== snapshot.text) reject('named tunnel config changed concurrently');
const temp = path.join(path.dirname(file), `.mso-app-route-${process.pid}-${randomBytes(6).toString('hex')}`);
const fd = fs.openSync(temp, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL, snapshot.stat.mode & 0o777);
try {
diff --git a/scripts/mso-gateway-app-route-recovery.test.ts b/scripts/mso-gateway-app-route-recovery.test.ts
index 278dae10..ee19eff1 100644
--- a/scripts/mso-gateway-app-route-recovery.test.ts
+++ b/scripts/mso-gateway-app-route-recovery.test.ts
@@ -52,8 +52,13 @@ describe("interrupted named connector swaps", () => {
fs.writeFileSync(path.join(f.dir, "deny-connector"), "1", { mode: 0o600 });
const first = ensure(f);
expect(first.status, first.stderr).toBe(1);
- expect(first.stderr).toContain("replacement connector did not start");
+ // The immediate-exit fixture can die before PID capture or during registration checks.
+ expect([
+ "mso gateway: replacement connector did not start; existing connector remains active",
+ "mso gateway: replacement connector did not register a tunnel connection; previous connector remains active",
+ ]).toContain(first.stderr.trim());
expect(JSON.parse(fs.readFileSync(f.stateFile, "utf8"))).toEqual(f.original);
+ expect(JSON.parse(fs.readFileSync(f.recordFile, "utf8"))).toEqual(f.record);
expect(() => process.kill(f.original.tunnelIdentity.pid, 0)).not.toThrow();
fs.unlinkSync(path.join(f.dir, "deny-connector"));
const second = ensure(f);
diff --git a/scripts/mso-gateway-named-config.test.ts b/scripts/mso-gateway-named-config.test.ts
index 1ff9a05d..c9079553 100644
--- a/scripts/mso-gateway-named-config.test.ts
+++ b/scripts/mso-gateway-named-config.test.ts
@@ -2,8 +2,9 @@ import { spawnSync } from "node:child_process";
import 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 YAML from "yaml";
+import { atomicReplace, readConfig } from "./lib/gateway-named-config.mjs";
const ROOT = path.resolve(__dirname, "..");
const HELPER = path.join(__dirname, "lib/gateway-named-config.mjs");
@@ -74,4 +75,42 @@ describe("named gateway YAML policy", () => {
expect(result.error).toBeUndefined();
expect(result.status).toBe(1);
});
+
+ it("rejects a different inode before rereading its contents", () => {
+ const f = fixture(), snapshot = readConfig(ROOT, f.file);
+ fs.renameSync(f.file, path.join(f.dir, "original.yml"));
+ fs.writeFileSync(f.file, snapshot.text, { mode: 0o600 });
+ const read = vi.spyOn(fs, "readFileSync");
+ try {
+ expect(() => atomicReplace(f.file, snapshot, snapshot.text)).toThrow(/changed concurrently/);
+ expect(read).not.toHaveBeenCalled();
+ } finally { read.mockRestore(); }
+ });
+
+ it("does not read a replacement symlink target during the final config comparison", () => {
+ const f = fixture(), snapshot = readConfig(ROOT, f.file);
+ const target = path.join(f.dir, "unrelated.yml"), retained = path.join(f.dir, "original.yml");
+ const unrelated = "unrelated private fixture\n", next = snapshot.text + "# retained configuration\n";
+ fs.writeFileSync(target, unrelated, { mode: 0o600 });
+ const originalRead = fs.readFileSync;
+ let swapped = false, followed = false, failure: unknown;
+ const read = vi.spyOn(fs, "readFileSync").mockImplementation((...args) => {
+ if (!swapped) {
+ fs.renameSync(f.file, retained);
+ fs.symlinkSync(target, f.file);
+ swapped = true;
+ }
+ const value = originalRead(...args);
+ if (value === unrelated) followed = true;
+ return value;
+ });
+ try { atomicReplace(f.file, snapshot, next); }
+ catch (error) { failure = error; }
+ finally { read.mockRestore(); }
+ expect(swapped).toBe(true);
+ expect(followed).toBe(false);
+ expect(failure).toBeUndefined();
+ expect(fs.readFileSync(target, "utf8")).toBe(unrelated);
+ expect(fs.readFileSync(f.file, "utf8")).toBe(next);
+ });
});
diff --git a/scripts/mso-heartbeat.test.ts b/scripts/mso-heartbeat.test.ts
index ca1312a8..900aee85 100644
--- a/scripts/mso-heartbeat.test.ts
+++ b/scripts/mso-heartbeat.test.ts
@@ -12,7 +12,8 @@ function fixture() {
const root = path.join(home, "repo with spaces % ' café\t"), bin = path.join(home, "bin");
fs.mkdirSync(path.join(root, "scripts/lib"), { recursive: true, mode: 0o700 });
fs.mkdirSync(bin, { mode: 0o700 });
- for (const file of ["gateway-config.sh", "gateway-common.sh", "private-state.sh", "heartbeat-cron.sh", "gateway-provider.sh", "gateway-tool.sh", "gateway-tunnel.sh", "gateway-cloudflare-edge.sh"])
+ for (const file of ["gateway-config.sh", "gateway-common.sh", "private-state.sh", "heartbeat-cron.sh", "gateway-provider.sh",
+ "gateway-tool.sh", "gateway-tunnel.sh", "gateway-named-config.mjs", "gateway-cloudflare-edge.sh"])
fs.copyFileSync(path.join(source, "scripts/lib", file), path.join(root, "scripts/lib", file));
fs.copyFileSync(path.join(source, "scripts/mso-heartbeat"), path.join(root, "scripts/mso-heartbeat"));
fs.mkdirSync(path.join(root, "security"));