Skip to content

Answer only this machine, and serve a built Docent on http - #44

Merged
vivecuervo7 merged 6 commits into
kit-3-idiomsfrom
request-guard
Nov 7, 2026
Merged

vivecuervo7 merged 6 commits into
kit-3-idiomsfrom
request-guard

Conversation

@vivecuervo7

@vivecuervo7 vivecuervo7 commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

What

  • Every request SvelteKit answers, pages included, must be addressed to this machine by name (localhost, 127.0.0.1, [::1], any port), and a change (anything but GET, HEAD, OPTIONS) that carries an Origin must come from Docent's own origin. This is one check in handle, refusal() in requestGuard.server.ts, which replaces the /mcp-only Host check. /mcp keeps its JSON-RPC error shape. The guard leaves a change with no Origin to the route, so agents' JSON requests are unaffected; a built Docent's SvelteKit still refuses a bodiless one with no Origin, as before.
  • No other site may frame Docent (frame-ancestors 'none'), since clicks inside a frame would otherwise come from Docent's own page.
  • A built Docent started with node build, which would take itself to be https, answers with a 500 that says to use npm start.
  • The routes that save or run a key command still require a request from Docent's own page (fromThisApp, now just the Origin comparison).
  • npm start runs server.js: adapter-node's handler on plain http, with each request told so, plus a clean shutdown on SIGINT/SIGTERM.
  • The sendWithoutBody workaround from Move to SvelteKit 3 #43 is removed.

Why

Only /mcp checked the Host, and only the provider routes checked Origin, so a domain rebound to this machine could reach every other route, including those that post reviews and resolve threads as the user. In dev, where SvelteKit's own CSRF check is off, any site could send changes.

Separately, adapter-node assumes https unless a proxy says otherwise, so a built Docent's URLs and the origin SvelteKit checks requests against both claimed https://. Saving a provider's key command was refused in production. SvelteKit 3 also forbids any remote-function call whose Origin isn't the server's own, ignoring trustedOrigins, so remote functions would have failed in production too. Setting paths.origin would only have patched SvelteKit's comparison: it bakes the port in at build time and leaves event.url claiming https.

How

Once the server's origin comes from the Host header, a rebound domain's Origin matches it, so SvelteKit's CSRF check can't stop rebinding. The Host allowlist in handle is what does, and its comment says so.

Checked on a production build with a copy of the data, before and after:

  • Saving a provider with a key command went from 403 to 200; a bodiless DELETE from the page went from 403 to reaching the route.
  • A rebound Host gets 403 on a page, /api and /mcp. A foreign or null Origin on a change gets 403. Agents' /mcp calls with no Origin go through, and a spoofed protocol header is overwritten.
  • Pages, _app assets and [::1] are served; the start page, Settings, Stats and a PR render in a browser with no errors.
  • Under node build, the start page shows the npm start message. A browser refuses to frame Docent from another origin.
  • SIGTERM exits 0. A port already in use fails with a message and exit code 1.

Also in dev: a rebound Host and a foreign-Origin change are both refused; pages and Vite's client load.

Not covered here: SvelteKit's remote-function origin check can't be exercised until a remote function exists. This PR makes event.url truthful, and the Stats slice will exercise the check against a production build. Separately, with HOST=localhost a built Docent listens on IPv6 ::1 only on this Mac, so 127.0.0.1 isn't reachable. That predates this PR and is tracked separately.

🤖 Generated with Claude Code

vivecuervo7 and others added 3 commits November 8, 2026 08:36
… from Docent's own pages

Only /mcp checked the Host before, and only the provider routes checked where a change came from, so a domain rebound to this machine could reach everything else, and in dev any site could send changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adapter-node assumes https unless a proxy says otherwise, so a built Docent's URLs and the origin SvelteKit checks requests against both claimed https: saving a provider's key command was refused, and remote functions would be too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s on http

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread web/package.json Resolved
Comment thread web/src/hooks.server.ts Resolved
Comment thread web/src/hooks.server.ts Resolved
Comment thread web/src/lib/api/http.server.ts Resolved
Comment thread web/src/lib/api/requestGuard.test.ts Resolved
vivecuervo7 and others added 3 commits November 8, 2026 08:51
…ther site frame it

Started with node build, a built Docent takes itself to be https and would refuse every change its own pages make. In a frame on another site, clicks the user was tricked into would come from Docent's own page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hook moves beside the request checks as one function, so its answers can be tested without starting Docent's background work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@vivecuervo7 vivecuervo7 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second review cycle, covering 6728de5..0ae5d84.

Comment thread web/src/lib/api/requestGuard.server.ts Resolved
Comment thread web/src/lib/api/requestGuard.server.ts Resolved
@vivecuervo7
vivecuervo7 merged commit 13dbbfe into kit-3-idioms Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant