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.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
fix(security): shell rc files hold API tokens — the credential denylist now says so
Rahmanb659ba7877ab
diff --git a/.env.example b/.env.exampleindex 2924134c..da6b0f4c 100644--- a/.env.example+++ b/.env.example@@ -22,7 +22,8 @@ OS_SESSION_SECRET=# OS_FS_READ_ROOTS=/# WRITE defaults to home + ~/projects (narrow, so the OS can't clobber system files).# OS_FS_WRITE_ROOTS=~:~/projects-# Sensitive home files (~/.ssh, ~/.aws, shell history, …) are blocked even within+# Sensitive home files (~/.ssh, ~/.aws, shell history, shell rc/profile files —+# where `export …_TOKEN=` lines live — …) are blocked even within# the read roots. Set =1 to lift that denylist (you accept the exposure).# OS_FS_ALLOW_SENSITIVE=1diff --git a/app/oauth/authorize/consent-form.tsx b/app/oauth/authorize/consent-form.tsxindex ed26fbea..aa5ac656 100644--- a/app/oauth/authorize/consent-form.tsx+++ b/app/oauth/authorize/consent-form.tsx@@ -14,11 +14,19 @@ const TIERS: { value: Scope; label: string; blurb: string }[] = [export function ConsentForm({clientName,redirectUri,+ denyUrl,ceiling,hidden,}: {clientName: string;redirectUri: string;+ /**+ * Pre-built on the server from the validated redirect target. `null` only if+ * that target would also be refused on the success path — unreachable from+ * this page today, since it renders no form in that case, but the type keeps+ * it that way rather than trusting the ordering of two files.+ */+ denyUrl: string | null;ceiling: Scope;hidden: Record<string, string>;}) {@@ -105,14 +113,24 @@ export function ConsentForm({<Button type="submit" disabled={busy} className="flex-1 [@media(pointer:coarse)]:min-h-[44px]">{busy ? "Connecting…" : "Allow"}</Button>- <Button- type="button"- variant="secondary"- className="flex-1 [@media(pointer:coarse)]:min-h-[44px]"- onClick={() => history.back()}- >- Cancel- </Button>+ {/* An anchor, not history.back(): declining has to REACH the client, or+ it waits on a callback that never comes and the user is left looking+ at a spinner. `denyUrl` is usually a different origin (chatgpt.com),+ which the Next router does not handle — a plain link does. */}+ {denyUrl ? (+ <Button asChild variant="secondary" className="flex-1 [@media(pointer:coarse)]:min-h-[44px]">+ <a href={denyUrl}>Cancel</a>+ </Button>+ ) : (+ <Button+ type="button"+ variant="secondary"+ className="flex-1 [@media(pointer:coarse)]:min-h-[44px]"+ onClick={() => history.back()}+ >+ Cancel+ </Button>+ )}</div></form>);diff --git a/app/oauth/authorize/page.tsx b/app/oauth/authorize/page.tsxindex eff99fcc..64d9d70b 100644--- a/app/oauth/authorize/page.tsx+++ b/app/oauth/authorize/page.tsx@@ -3,6 +3,7 @@ import { notFound } from "next/navigation";import { requireSession } from "@/lib/auth/require-session";import { getClient } from "@/lib/mcp/store";import { isAllowedRedirect } from "@/lib/mcp/pkce";+import { denyUrl, selfUrl } from "@/lib/mcp/redirect";import { mcpEnabled, maxScope } from "@/lib/mcp/scope";import { ConsentForm } from "./consent-form";@@ -33,16 +34,34 @@ export default async function AuthorizePage({const method = one("code_challenge_method");if (!(await requireSession())) {+ // The request is KEPT. This used to link to `/` and tell the visitor to+ // "start the connection again from the client", which threw the whole+ // authorization request away: ChatGPT had already generated its PKCE+ // verifier and state, so going back meant restarting the flow from the+ // connector dialog — and most people read that screen as "it is broken".+ //+ // mso's unlock is a client-side gate over a JSON login route, so there is no+ // server-side `?next=` to hand off to. What works without inventing one: put+ // the unlock in a SECOND tab and leave this one where it is. The session is+ // a cookie, so once it exists this exact URL renders the consent screen —+ // Continue is a plain re-request of the same query string, nothing stored.+ const here = selfUrl(q);return (<Shell>- <h1 className="text-lg font-semibold">Sign in first</h1>+ <h1 className="text-lg font-semibold">Unlock mso to continue</h1><p className="mt-2 text-sm text-muted-foreground">- Open mso, unlock it on this device, then start the connection again from the client. This page- cannot authorize anything on its own.+ This page cannot authorize anything on its own — it needs your signed-in session. Unlock mso in+ a new tab, then come back here and press Continue. <strong>Do not close this tab:</strong> it is+ holding the request the client just made.</p>- <Link className="mt-4 inline-block text-sm underline" href="/" prefetch={false}>- Open mso- </Link>+ <div className="mt-4 flex flex-wrap gap-3 text-sm">+ <a className="underline" href="/" target="_blank" rel="noopener noreferrer">+ Unlock mso in a new tab+ </a>+ <Link className="underline" href={here} prefetch={false}>+ Continue+ </Link>+ </div></Shell>);}@@ -65,11 +84,25 @@ export default async function AuthorizePage({}const client = await getClient(clientId);++ // Where Cancel goes. Built HERE, from the redirect target this page already+ // validated, rather than in the browser — the deny path must not be the one+ // place a URL gets assembled from unchecked input.+ //+ // A refusal is REPORTED, not just navigated away from. Cancel used to call+ // `history.back()`, which tells the client nothing at all: ChatGPT sits on its+ // connector dialog waiting for a callback that will never arrive, and the user+ // sees a spinner rather than "you declined". RFC 6749 §4.1.2.1 — and `state`+ // rides along, because a client that cannot match the response to its own+ // request is required to discard it.+ const deny = denyUrl(redirectUri, one("state"));+return (<Shell><ConsentFormclientName={client?.name ?? clientId}redirectUri={redirectUri}+ denyUrl={deny}ceiling={maxScope()}hidden={{client_id: clientId,diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex e63d8ed0..f619f7bf 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -16,6 +16,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.**Fixed**+- `security` shell rc files hold API tokens — the credential denylist now says so- `changelog` a regeneration commit must not appear in the file it regenerates- `deps` pin nanoid >=3.3.18 — the audit gate has been failing on main- `managed-apps` say why a dashboard is missing instead of silently opening a terminaldiff --git a/lib/host/paths-credentials.test.ts b/lib/host/paths-credentials.test.tsindex 3168d39b..52f2ff04 100644--- a/lib/host/paths-credentials.test.ts+++ b/lib/host/paths-credentials.test.ts@@ -42,6 +42,22 @@ describe("recursive credential guard", () => {expect(isSensitivePath(path.join(fakeHome, ".codex", "auth.json"))).toBe(true);});+ it("blocks the shell rc + profile files, because that is where CLI tokens live", () => {+ // Found by audit, not by theory: the box this was written on had eight+ // `export …_TOKEN=` lines in ~/.bashrc, put there by tooling that says "add+ // this to your shell profile". Shell HISTORY was already denied; the file that+ // defines the environment is the richer target.+ vi.stubEnv("HOME", fakeHome);+ for (const name of [".bashrc", ".zshrc", ".profile", ".bash_profile", ".zshenv"]) {+ expect(isSensitivePath(path.join(fakeHome, name)), name).toBe(true);+ }+ expect(isSensitivePath(path.join(fakeHome, ".config", "fish", "config.fish"))).toBe(true);+ // Still a denylist, not a ban on dotfiles: an rc file for something that holds+ // no credentials stays readable.+ expect(isSensitivePath(path.join(fakeHome, ".vimrc"))).toBe(false);+ expect(isSensitivePath(path.join(fakeHome, ".gitconfig"))).toBe(false);+ });+it("excludes a credential dir nested under the zip base", () => {vi.stubEnv("HOME", fakeHome);expect(isSensitivePath(parent)).toBe(false); // the exact gap this guard closesdiff --git a/lib/host/paths.ts b/lib/host/paths.tsindex 52c3c88e..4dd369de 100644--- a/lib/host/paths.ts+++ b/lib/host/paths.ts@@ -85,6 +85,16 @@ const SENSITIVE_HOME = [".local/share/camoufox", ".local/state/camoufox", ".vnc",// database creds + password-manager CLIs".pgpass", ".config/op", ".config/lpass",+ // SHELL RC + PROFILE FILES. Not config-shaped paranoia: `export FOO_TOKEN=…` in+ // ~/.bashrc is how most people (and this box — 8 of them the day this was added)+ // keep API keys for CLIs, and every installer that says "add this to your shell+ // profile" puts one there. The list already blocks shell HISTORY for the same+ // reason; the file that DEFINES the environment is the richer target of the two.+ // Editing them from the cockpit is a real loss — that is what OS_FS_ALLOW_SENSITIVE+ // is for, and a terminal window is right there.+ ".bashrc", ".bash_profile", ".bash_login", ".bash_aliases", ".profile",+ ".zshrc", ".zprofile", ".zshenv", ".zlogin", ".kshrc",+ ".config/fish/config.fish", ".config/fish/conf.d",// loose private keys saved outside ~/.ssh (heredoc dumps, exports, etc.)"id_rsa", "id_ed25519", "id_ecdsa", "id_dsa",];diff --git a/lib/host/self-update.ts b/lib/host/self-update.tsindex aa9d68e4..6416fc7c 100644--- a/lib/host/self-update.ts+++ b/lib/host/self-update.ts@@ -138,6 +138,9 @@ async function readLog(): Promise<string> {*/export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus> {const buildSha = (process.env.NEXT_PUBLIC_COMMIT_SHA ?? "").trim();+ // Read ONCE: the panel polls this every 3s while a build runs, and the log is+ // the biggest thing in the response.+ const log = await readLog();const base: UpdateStatus = {supported: false,reason: null,@@ -150,7 +153,7 @@ export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus>dirty: false,running: false,remoteChecked: false,- log: await readLog(),+ log,};const inside = await git(["rev-parse", "--is-inside-work-tree"]);@@ -173,7 +176,7 @@ export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus>remoteChecked = fetched.code === 0;}- const [count, log] = await Promise.all([+ const [count, commitLog] = await Promise.all([git(["rev-list", "--count", "HEAD..origin/main"]),git(["log", "--format=%h%x1f%s%x1f%cs", `-${MAX_COMMITS}`, "HEAD..origin/main"]),]);@@ -188,11 +191,11 @@ export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus>// dev server) must not be reported as permanently stale.pendingBuild: Boolean(buildSha) && current !== "unknown" && buildSha !== current,behind: count.code === 0 ? Number(count.stdout.trim()) || 0 : 0,- commits: log.code === 0 ? parseCommits(log.stdout) : [],+ commits: commitLog.code === 0 ? parseCommits(commitLog.stdout) : [],dirty: status.stdout.trim().length > 0,running,remoteChecked,- log: await readLog(),+ log,};}diff --git a/lib/mcp/redirect.test.ts b/lib/mcp/redirect.test.tsnew file mode 100644index 00000000..af97c007--- /dev/null+++ b/lib/mcp/redirect.test.ts@@ -0,0 +1,88 @@+import { describe, expect, it } from "vitest";+import { denyUrl, selfUrl } from "./redirect";++const CHATGPT = "https://chatgpt.com/connector_platform_oauth_redirect";++describe("denyUrl", () => {+ it("reports the refusal back to the client instead of going nowhere", () => {+ // The bug this replaces: Cancel called history.back(), so ChatGPT waited on+ // a callback that never came and the user just saw a spinner.+ const url = new URL(denyUrl(CHATGPT, "st-1") as string);+ expect(url.origin + url.pathname).toBe(CHATGPT);+ expect(url.searchParams.get("error")).toBe("access_denied");+ expect(url.searchParams.get("state")).toBe("st-1");+ });++ it("omits state when the client sent none, rather than sending an empty one", () => {+ expect(denyUrl(CHATGPT, "")).not.toContain("state=");+ });++ it("keeps a query the redirect target already carried", () => {+ const url = denyUrl("https://chatgpt.com/cb?tenant=acme", "s") as string;+ expect(url).toContain("tenant=acme");+ expect(url).toContain("error=access_denied");+ });++ it("percent-encodes a hostile state instead of splitting the query", () => {+ const url = denyUrl(CHATGPT, "a&code=evil") as string;+ expect(new URL(url).searchParams.get("code")).toBeNull();+ });++ it("refuses a target the success path would also refuse", () => {+ // Declining must not be a softer gate than approving.+ expect(denyUrl("http://evil.test/cb", "s")).toBeNull();+ expect(denyUrl("javascript:alert(1)", "s")).toBeNull();+ expect(denyUrl("not a url", "s")).toBeNull();+ });++ it("allows loopback, which is how a desktop client receives the answer", () => {+ expect(denyUrl("http://127.0.0.1:41234/cb", "s")).toContain("error=access_denied");+ });+});++describe("selfUrl", () => {+ const REQ = {+ response_type: "code",+ client_id: "mcpc_abc",+ redirect_uri: CHATGPT,+ code_challenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",+ code_challenge_method: "S256",+ state: "st-1",+ scope: "read",+ };++ it("round-trips the whole request, so unlocking does not lose it", () => {+ // The bug this replaces: the unauthenticated screen linked to `/`, throwing+ // away a request the client had already committed a PKCE verifier to.+ const params = new URL(`https://mso.test${selfUrl(REQ)}`).searchParams;+ for (const [key, value] of Object.entries(REQ)) {+ expect(params.get(key), key).toBe(value);+ }+ });++ it("carries `resource`, which ChatGPT sends", () => {+ const params = new URL(+ `https://mso.test${selfUrl({ ...REQ, resource: "https://mso.rahmanef.com/mcp" })}`,+ ).searchParams;+ expect(params.get("resource")).toBe("https://mso.rahmanef.com/mcp");+ });++ it("drops anything the flow does not read", () => {+ const url = selfUrl({ ...REQ, utm_source: "x", "<script>": "y" });+ expect(url).not.toContain("utm_source");+ expect(url).not.toContain("script");+ });++ it("takes the first value of a repeated parameter, matching what the page reads", () => {+ const url = selfUrl({ ...REQ, redirect_uri: [CHATGPT, "https://evil.test/cb"] });+ expect(url).not.toContain("evil.test");+ });++ it("stays a relative path — it is a link back to this same page", () => {+ expect(selfUrl(REQ).startsWith("/oauth/authorize?")).toBe(true);+ });++ it("degrades to the bare path when there is nothing to carry", () => {+ expect(selfUrl({})).toBe("/oauth/authorize");+ });+});diff --git a/lib/mcp/redirect.ts b/lib/mcp/redirect.tsnew file mode 100644index 00000000..5a788214--- /dev/null+++ b/lib/mcp/redirect.ts@@ -0,0 +1,67 @@+import { isAllowedRedirect } from "./pkce";++/**+ * The two URLs the consent page has to build, kept out of the page so they can+ * be tested. Both were previously inline and neither was covered:+ *+ * - the deny URL was not built at all — Cancel called `history.back()`, so a+ * refusal never reached the client and the connector dialog hung;+ * - the "come back here" URL did not exist — an unauthenticated visitor was+ * sent to `/` and the whole authorization request was discarded.+ */++/** Only the params a re-request needs. Anything else a client sent is dropped. */+const CARRIED = [+ "response_type",+ "client_id",+ "redirect_uri",+ "code_challenge",+ "code_challenge_method",+ "state",+ "scope",+ "resource",+] as const;++/**+ * The same authorization request, addressable again after the visitor unlocks+ * mso in another tab. Nothing is stored: the request lives in this URL.+ *+ * Rebuilt from an allowlist rather than echoed wholesale — the query string is+ * attacker-influenced, and a link this page renders should carry only what the+ * flow actually reads.+ */+export function selfUrl(query: Record<string, string | string[] | undefined>): string {+ const params = new URLSearchParams();+ for (const key of CARRIED) {+ const raw = query[key];+ const value = Array.isArray(raw) ? raw[0] : raw;+ // A repeated parameter takes the first value, matching what the page reads.+ if (typeof value === "string" && value.length > 0) params.set(key, value);+ }+ const qs = params.toString();+ return qs.length > 0 ? `/oauth/authorize?${qs}` : "/oauth/authorize";+}++/**+ * Where Cancel goes: back to the client, saying it was refused.+ *+ * RFC 6749 §4.1.2.1. `state` rides along because a client that cannot match a+ * response to its own request must discard it — omitting it on the denial path+ * breaks well-behaved clients specifically.+ *+ * Returns null when the target is not one we would have redirected to anyway.+ * The caller renders no Cancel link in that case rather than a broken one: a+ * refusal is not a reason to relax the check that guards the success path.+ */+export function denyUrl(redirectUri: string, state: string): string | null {+ if (!isAllowedRedirect(redirectUri)) return null;+ let url: URL;+ try {+ url = new URL(redirectUri);+ } catch {+ return null;+ }+ url.searchParams.set("error", "access_denied");+ if (state) url.searchParams.set("state", state);+ return url.toString();+}diff --git a/vitest.config.mts b/vitest.config.mtsindex 13952cdb..ba7d4531 100644--- a/vitest.config.mts+++ b/vitest.config.mts@@ -56,10 +56,13 @@ export default defineConfig({"**/.next/**",],thresholds: {- statements: 19,- branches: 18,- functions: 14,- lines: 19,+ // Ratcheted 2026-08-17 from 19/18/14/19 after the update-route, path,+ // download and env-reconciliation tests landed. Measured 20.36 / 19.08 /+ // 15.11 / 20.76 — these sit a hair under, as the comment above requires.+ statements: 20,+ branches: 18.5,+ functions: 15,+ lines: 20.5,},},},