From 4cebb42a4ab512f0493302ccc5c2487699798219 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Nov 2026 02:05:32 +0000 Subject: [PATCH 1/2] fix(site): refuse dev desk mount when Astro binds beyond loopback By default the integration skips /admin and /api/dev-content when server.host is not loopback-only, unless edit.allowNonLoopback is set. Co-authored-by: Charles Berret --- docs/ARE_YOU_INSANE.md | 4 +++- packages/site/src/config.ts | 7 ++++++ packages/site/src/index.test.ts | 38 +++++++++++++++++++++++++++++++-- packages/site/src/index.ts | 23 +++++++++++++++++++- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/docs/ARE_YOU_INSANE.md b/docs/ARE_YOU_INSANE.md index 3d291fb..6c4555b 100644 --- a/docs/ARE_YOU_INSANE.md +++ b/docs/ARE_YOU_INSANE.md @@ -51,6 +51,8 @@ CORS is a browser rule, and it is a different one. Vite 6.4 defaults `server.cor Copying the marquee's `server.host: true` onto a host that mounts the handler exposes the desk on every interface that process listens on. +By default, `@shellside/site` does not mount `/admin` or `/api/dev-content` when Astro's `server.host` is not loopback-only (`server.host: true`, `0.0.0.0`, and the like). It logs one line at setup and mounts nothing unless `edit.allowNonLoopback: true` is set in `site.config`. + ## What the path grammar holds `parseContentPath` (`packages/edit-protocol/src/paths.ts`) accepts `kind:id:field` up to 200 characters. An id must match `[a-z0-9][a-z0-9._-]*`. A field must be dotted identifiers (`title`, `links.0.href`). A slash, a space, or an id of `..` fails the parse, and the handler returns 400. Work files are `/.md` with that id. YAML lists are rewritten with `yaml.dump`, so a value is a datum in the document. @@ -68,7 +70,7 @@ The portfolio, the console, `list.txt`, and `llms.txt` are supposed to read one ## If you run one - Mount `createDevContentHandler` only where `import.meta.env.DEV` is the real dev flag, and pass that flag as `isDev`. -- Leave the dev server on loopback. `server.host: true` listens on every interface, and the desk's host check will not notice. +- Leave the dev server on loopback. `server.host: true` listens on every interface; the request `Host` check will not notice. The kit's mount gate refuses non-loopback binds by default — do not set `edit.allowNonLoopback: true` unless you mean to expose the desk on every interface the process listens on. - Build the VFS from `isPublicItem`. Run `leakAudit` on `dist`. - Pass a real allowlist. An omitted policy allows every well-formed path. - Escape anything a console command sends to `out()`. diff --git a/packages/site/src/config.ts b/packages/site/src/config.ts index c826672..34c50ec 100644 --- a/packages/site/src/config.ts +++ b/packages/site/src/config.ts @@ -125,6 +125,13 @@ export type ShellsiteConfig = { * Omit for a content-only desk. */ look?: string; + /** + * When false (default), the host refuses to mount the dev desk in + * `astro dev` unless Astro's `server.host` is loopback-only. Set + * `true` only if you accept exposing the write API on every address + * the dev server binds to (`server.host: true` and the like). + */ + allowNonLoopback?: boolean; }; }; diff --git a/packages/site/src/index.test.ts b/packages/site/src/index.test.ts index f46545c..fe2e0e9 100644 --- a/packages/site/src/index.test.ts +++ b/packages/site/src/index.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { defineShellsiteConfig, shellsite } from "./index.js"; +import { defineShellsiteConfig, isLoopbackServerBind, shellsite } from "./index.js"; test("config is plain data (serializable)", () => { const c = defineShellsiteConfig({ @@ -45,6 +45,40 @@ test("virtual config plugin emits the config", () => { assert.ok(plugin.load(id)!.includes('"name":"T"')); }); +test("isLoopbackServerBind matches Astro server.host shapes", () => { + assert.equal(isLoopbackServerBind(undefined), true); + assert.equal(isLoopbackServerBind(false), true); + assert.equal(isLoopbackServerBind(true), false); + assert.equal(isLoopbackServerBind("0.0.0.0"), false); + assert.equal(isLoopbackServerBind("127.0.0.1"), true); + assert.equal(isLoopbackServerBind("localhost"), true); +}); + +test("devDesk skips mount when server.host is true unless allowNonLoopback", () => { + const edit = { + files: { work: "work" }, + policy: "./src/policy.ts", + }; + const run = (allowNonLoopback?: boolean) => { + const routes: string[] = []; + const i = shellsite({ + identity: { name: "T" }, + collections: {}, + surfaces: { devDesk: true }, + edit: { ...edit, ...(allowNonLoopback ? { allowNonLoopback: true } : {}) }, + }); + (i.hooks as Record)["astro:config:setup"]({ + injectRoute: (r: { pattern: string }) => routes.push(r.pattern), + updateConfig: () => {}, + command: "dev", + config: { root: new URL("file:///site/"), server: { host: true } }, + }); + return routes; + }; + assert.equal(run().includes("/api/dev-content"), false); + assert.equal(run(true).includes("/api/dev-content"), true); +}); + test("devDesk injects /api/dev-content only in dev and only with edit", () => { const mk = (devDesk: boolean, withEdit: boolean) => shellsite({ @@ -67,7 +101,7 @@ test("devDesk injects /api/dev-content only in dev and only with edit", () => { plugins = u.vite?.plugins ?? []; }, command, - config: { root: new URL("file:///site/") }, + config: { root: new URL("file:///site/"), server: { host: "127.0.0.1" } }, }); const want = command === "dev" && withEdit; assert.equal( diff --git a/packages/site/src/index.ts b/packages/site/src/index.ts index 9c570a4..b94fe05 100644 --- a/packages/site/src/index.ts +++ b/packages/site/src/index.ts @@ -32,6 +32,19 @@ export { isPublicItem } from "@shellside/content-model"; export const SHELLSITE_CONFIG_ID = "virtual:shellsite/config"; const RESOLVED_CONFIG_ID = "\0" + SHELLSITE_CONFIG_ID; +const LOOPBACK_BIND_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]); + +/** Whether Astro's dev `server.host` binds only on loopback (default safe). */ +export function isLoopbackServerBind(host?: string | boolean): boolean { + if (host === undefined || host === false) return true; + if (host === true) return false; + const h = host.trim().toLowerCase(); + if (LOOPBACK_BIND_HOSTS.has(h)) return true; + if (h === "0.0.0.0" || h === "::" || h === "*") return false; + if (/^127(?:\.\d{1,3}){3}$/.test(h)) return true; + return false; +} + function configPlugin(config: ShellsiteConfig): Plugin { return { name: "shellsite-config", @@ -55,8 +68,16 @@ export function shellsite(config: ShellsiteConfig): AstroIntegration { "astro:config:setup": ({ injectRoute, updateConfig, command, config: astroConfig }: any) => { // The desk mounts only in `astro dev` — a build never sees the // route, the virtual module, or the site's edit modules. - const deskOn = + const deskWanted = Boolean(config.surfaces.devDesk && config.edit) && command === "dev"; + const bindLoopback = isLoopbackServerBind(astroConfig?.server?.host); + const allowWideBind = config.edit?.allowNonLoopback === true; + const deskOn = deskWanted && (bindLoopback || allowWideBind); + if (deskWanted && !deskOn) { + console.log( + "@shellside/site: dev desk not mounted because Astro server.host is not loopback (set edit.allowNonLoopback: true to opt in)", + ); + } if (deskOn) { injectRoute({ pattern: "/api/dev-content", From 7368d74d10909aebc6e9c3efee89d045ef40eeac Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Nov 2026 02:09:26 +0000 Subject: [PATCH 2/2] fix(reference): align desk edit.files with toy fixture Points profile at profile/profile.yaml and drops yaml paths the toy fixture does not provide so check-desk smoke can pass. Co-authored-by: Charles Berret --- apps/reference/site.config.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/reference/site.config.ts b/apps/reference/site.config.ts index 531fd9e..0412a82 100644 --- a/apps/reference/site.config.ts +++ b/apps/reference/site.config.ts @@ -16,9 +16,7 @@ export default defineShellsiteConfig({ files: { work: "work", writing: "writing.yaml", - records: "records.yaml", - profile: "profile.yaml", - pageCopy: "page-copy.yaml", + profile: "profile/profile.yaml", }, policy: "./src/lib/edit-policy.ts", },