Repository navigation
feat(cli): serve the Console document with a nonce-based content-security-policy - #25569
Conversation
…rity-policy Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV
📓 Docs Drift CheckThis PR changes 1 package(s): 3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 2 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 30 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 6d9649ac84c9684896b9355e66e7c29c6d0c21ba && git checkout 6d9649ac84c9684896b9355e66e7c29c6d0c21ba
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9c43e19f659c40bb065601bda50c7e05250169f2 e6d0e56d51d32bb32756c0f8f1cea85c7ad448a9 && git checkout -B drift-repro 9c43e19f659c40bb065601bda50c7e05250169f2 && git merge --no-ff e6d0e56d51d32bb32756c0f8f1cea85c7ad448a9
node scripts/docs-audit/affected-docs.mjs --json 9c43e19f659c40bb065601bda50c7e05250169f2
|
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV
Requested by Tesla · project thread
Summary
The Console document (every HTML answer under
/_console/) is now served with a nonce-basedcontent-security-policyresponse header. Until now only API responses carried a policy (packages/runtime/src/security/security-headers.ts), and the Console shell carried none.createConsoleStaticPlugin(packages/cli/src/utils/console.ts) draws a fresh 128-bit nonce per response. It names the nonce in the header and stamps it on every script element of the served document: the build's inline scripts, its module entry, and the server's own react-pages disable script.os devandos startboth spawnos serve, which mounts it, and the Docker image's command isos start. A host that mounts the plugin itself through@objectstack/cli/consolegets the same header.Clause-②: no
Metadata-protocol: none
The policy
Each allowance was measured against the published
@objectstack/console@18.0.0build (itsindex.html, itsassets/) and the objectui source at the pinned.objectui-sha(2958f17e). The reason for each is written next to the policy in the code.default-src'self'script-src'self' 'nonce-…' 'wasm-unsafe-eval', plus'unsafe-eval'only while the react-pages tier is on'wasm-unsafe-eval'is for shiki (the AI chat's code highlighter), which compiles WebAssembly. Thekind:'react'runtime (ADR-0081) evaluates page source withFunction, so'unsafe-eval'followsOS_PAGE_REACT. That flag is read once per document, so the disable script and the policy always agree.style-src'self' 'unsafe-inline'styleattributes, and style elements libraries insert at run time without a nonce.img-src'self' data: blob: https:connect-src'self' https://demotiles.maplibre.org, plus the error-reporting DSN's origin when the runtime serves one, plusOS_CONSOLE_CSP_CONNECT_SRC'self'also covers the same-origin WebSocket and event stream), and the map view's default style host. The DSN origin is read from the sameGET /api/v1/runtime/configanswer the document's branding is already read from.object-src'none'base-uri'self'frame-ancestors'self', omitted on/_console/f/*What an operator may notice
OS_CONSOLE_CSP_CONNECT_SRC. It is a space-separated list of extraconnect-srcsources: a scheme (https:) or a scheme with a host (https://tiles.example.com). It exists because a map view's authoredmapStyleis fetched straight from its host, and the server cannot know that host ahead of the request. It is read once at boot. An entry outside that grammar (a keyword,*, a bare host, or anything carrying;or quotes) stops the boot with a message naming it.script-src, because a CDN host there admits every file that CDN serves. The editor therefore shows the plain-text fallback objectui already ships for this case.Verification
Tests: a new suite,
packages/cli/src/utils/console.content-security-policy.test.ts, with 17 cases. It boots the real plugin on a real Hono app, and adds the realRuntimeConfigPluginfor the DSN case. It checks:.htmlhit, and absent on assets;'unsafe-eval'is present by default and absent withOS_PAGE_REACT=off;frame-ancestorsis omitted on/_console/f/*and kept on/_console/forms/*;OS_CONSOLE_CSP_CONNECT_SRCextras are added in order, and five malformed values refuse the boot.Local results, at head
9182f4b9:@objectstack/cliunit tier (vitest run --project unit) passes: 328 files, 4829 tests. The integration tier is left to CI, because the diff touches no spawn entry.vitest run --project unitpasses on the new suite plusconsole.branded-head,console.public-form-redirect,console.asset-cache,console.not-built,console.sha-drift,published-subpath-console.pinandruntime-assets. The existing suites pass unchanged.pnpm --filter @objectstack/cli typecheck(tsc pluscheck:test-typecheck) exits 0.eslint --no-inline-configon both touched files exits 0.node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 69 commands, and all 69 exit 0. The--ranreconciliation reports 69 derived, 69 run, 0 not measured.Browser smoke:
pnpm dev -- --fresh -p <port>(the showcase), serving the published@objectstack/console@18.0.0dist, driven by Playwright Chromium.kind:'react'page (Task Desk), a map page, the component gallery, the capability map,/ai, and a public form URL.securitypolicyviolationlistener was installed before any page script ran, and console messages were captured too.'unsafe-eval'presentOS_PAGE_REACT=off'unsafe-eval'absentIn both runs the map rendered its canvas. The Task Desk react page rendered with the tier on, and showed the disabled notice with it off.
frame-ancestorswas absent only on the public form URL.Acceptance notes
OS_PAGE_REACT=off, each document load reports onescript-srcevalrefusal from the Console bundle. The source is zod v4's capability probe: it triesFunction('')once inside a try/catch, to decide whether its JIT can be used, and falls back when refused. Nothing breaks, and the page reports no error. The probe is skipped when zod'sjitlessconfig is set, so the clean fix is objectui-side: setz.config({ jitless: true })in the Console, at least when react pages are off. That is outside this repository and is reported to the maintainer rather than worked around here, for example by allowing'unsafe-eval'.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV