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): validate the model half of a provider/model ref
Abdurrahman Fakhruladc2d994a916
diff --git a/lib/config/store-security.test.ts b/lib/config/store-security.test.tsindex 6a7fee87..d9c952e0 100644--- a/lib/config/store-security.test.ts+++ b/lib/config/store-security.test.ts@@ -83,3 +83,47 @@ describe("config record safety", () => {expect(Object.prototype).not.toHaveProperty("custom-two");});});++// The provider half of a `provider/model` ref was validated; the model half was not, so a stored+// config value could carry arbitrary text into an outbound request body. CodeQL flagged that as+// js/file-access-to-http (config -> model id -> request). This pins the validation, and the+// legitimate catalogue shapes it must keep accepting.+describe("model id safety", () => {+ it("accepts the shapes real catalogues use", async () => {+ const { safeModelId } = await load();+ for (const ok of [+ "gpt-6.1-sol",+ "claude-opus-5-5-high",+ "meta-llama/llama-4-405b", // OpenRouter vendor/model+ "deepseek-v4.1-flash:free", // OpenRouter :free suffix+ "Qwen2.5_Coder_32B",+ "o4-mini",+ ]) {+ expect(safeModelId(ok), ok).toBe(ok);+ }+ });++ it("rejects anything that would travel into a request", async () => {+ const { safeModelId } = await load();+ for (const bad of [+ "", // empty+ " model", // leading space+ "model\ninjected", // newline+ "model\r\nX-Injected: 1", // header-ish injection+ "../../etc/passwd", // traversal+ "a/../b",+ "model?x=1", // query injection+ "model#frag",+ "__proto__", // reserved+ "x".repeat(201), // over the length cap+ ]) {+ expect(() => safeModelId(bad), JSON.stringify(bad)).toThrow(/invalid model id/);+ }+ });++ it("rejects a bad stored model before it reaches a request", async () => {+ const { writeConfig, resolveModelRef } = await load();+ await writeConfig({ provider: "custom-one", model: "bad\nmodel" });+ await expect(resolveModelRef()).rejects.toThrow(/invalid model id/);+ });+});diff --git a/lib/config/store.ts b/lib/config/store.tsindex 6198dc39..a037caa2 100644--- a/lib/config/store.ts+++ b/lib/config/store.ts@@ -62,6 +62,20 @@ export function safeProviderId(value: string): string {return value;}+// A model id is not free text: it is spliced into a provider request body and, on some+// providers, into a path. Nothing validated the model half of a `provider/model` ref — only the+// provider was checked — so a config value could carry anything into an outbound request.+// Deliberately permissive about the shapes real catalogues use (OpenRouter's `vendor/model`,+// `:free` suffixes, dots and underscores) and strict about everything else.+const MODEL_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:\/-]{0,199}$/;++export function safeModelId(value: string): string {+ if (!MODEL_ID_RE.test(value) || RESERVED_RECORD_KEYS.has(value) || value.includes("..")) {+ throw new Error("invalid model id");+ }+ return value;+}+function recordValue<T>(record: Record<string, T> | undefined, key: string): T | undefined {return Object.entries(record ?? {}).find(([name]) => name === key)?.[1];}@@ -98,7 +112,11 @@ export async function writeConfig(patch: OsConfig, tenant?: string): Promise<voiexport async function resolveModelRef(tenant?: string): Promise<string> {const c = await readConfig(tenant);const provider = safeProviderId(c.provider || DEFAULT_PROVIDER);- return `${provider}/${c.model || defaultModelFor(provider)}`;+ // Validated here as well as at the parse boundary, because this is the path a stored config+ // takes into an outbound request. Throwing on a bad value is correct: the caller turns it into+ // a 400, and a model id that cannot be sent is not a model id.+ const model = safeModelId(c.model || defaultModelFor(provider));+ return `${provider}/${model}`;}export function hostCredentialStore() {