Skip to content

feat(cli): serve the Console document with a nonce-based content-security-policy - #25569

Merged
os-tesla merged 5 commits into
mainfrom
claude/project-thread-9xn5vl
Oct 25, 2026
Merged

os-tesla merged 5 commits into
mainfrom
claude/project-thread-9xn5vl

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread

Summary

The Console document (every HTML answer under /_console/) is now served with a nonce-based content-security-policy response 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.
  • The nonce is stamped before any request-time value (branding title and meta tags) is written into the document, so no runtime value can carry it.
  • This plugin is the one place the document is served from. os dev and os start both spawn os serve, which mounts it, and the Docker image's command is os start. A host that mounts the plugin itself through @objectstack/cli/console gets the same header.
  • Runtime is unchanged.

Clause-②: no
Metadata-protocol: none

The policy

Each allowance was measured against the published @objectstack/console@18.0.0 build (its index.html, its assets/) and the objectui source at the pinned .objectui-sha (2958f17e). The reason for each is written next to the policy in the code.

Directive Value Why
default-src 'self' Covers maplibre's module workers (started from its own file), the PWA manifest and same-origin frames (the Studio live canvas). The build ships no web fonts.
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. The kind:'react' runtime (ADR-0081) evaluates page source with Function, so 'unsafe-eval' follows OS_PAGE_REACT. That flag is read once per document, so the disable script and the policy always agree.
style-src 'self' 'unsafe-inline' The shell's boot-splash style element, React/Radix style attributes, and style elements libraries insert at run time without a nonce.
img-src 'self' data: blob: https: Inline SVG icons in the stylesheets, upload previews, and externally hosted branding logos and favicons, avatars, image field values and email-template images.
connect-src 'self' https://demotiles.maplibre.org, plus the error-reporting DSN's origin when the runtime serves one, plus OS_CONSOLE_CSP_CONNECT_SRC The API ('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 same GET /api/v1/runtime/config answer the document's branding is already read from.
object-src 'none'
base-uri 'self' Only the server's own base element.
frame-ancestors 'self', omitted on /_console/f/* The public-forms screen gives authors an iframe snippet that embeds the public form page on their own site.

What an operator may notice

  • New OS_CONSOLE_CSP_CONNECT_SRC. It is a space-separated list of extra connect-src sources: a scheme (https:) or a scheme with a host (https://tiles.example.com). It exists because a map view's authored mapStyle is 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.
  • Framing from another origin is refused, except on the public form page.
  • The Studio's code editor (Monaco) loads its core from a public CDN. The policy deliberately lists no CDN in 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 real RuntimeConfigPlugin for the DSN case. It checks:

  • the header is present on the shell, on an SPA fallback and on a direct .html hit, and absent on assets;
  • the nonce differs across 5 responses;
  • every script element in the served document carries the header's nonce, including an uppercase tag and the injected react-pages disable script;
  • 'unsafe-eval' is present by default and absent with OS_PAGE_REACT=off;
  • frame-ancestors is omitted on /_console/f/* and kept on /_console/forms/*;
  • the DSN origin appears without its key;
  • OS_CONSOLE_CSP_CONNECT_SRC extras are added in order, and five malformed values refuse the boot.

Local results, at head 9182f4b9:

  • The full @objectstack/cli unit 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 unit passes on the new suite plus console.branded-head, console.public-form-redirect, console.asset-cache, console.not-built, console.sha-drift, published-subpath-console.pin and runtime-assets. The existing suites pass unchanged.
  • pnpm --filter @objectstack/cli typecheck (tsc plus check:test-typecheck) exits 0. eslint --no-inline-config on both touched files exits 0.
  • Gates: node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 69 commands, and all 69 exit 0. The --ran reconciliation reports 69 derived, 69 run, 0 not measured.

Browser smoke: pnpm dev -- --fresh -p <port> (the showcase), serving the published @objectstack/console@18.0.0 dist, driven by Playwright Chromium.

  • The run signed in as the seeded admin and visited eight routes: home, the showcase app, a kind:'react' page (Task Desk), a map page, the component gallery, the capability map, /ai, and a public form URL.
  • A securitypolicyviolation listener was installed before any page script ran, and console messages were captured too.
  • A negative control at the end of each run proved the listener can see a refusal. It inserts an inline script without a nonce, and a script from the Monaco CDN path. Both were refused and both were reported.
Run Header on the wire Violations on the 8 routes Page errors
react pages on (default) 'unsafe-eval' present 0 0
OS_PAGE_REACT=off 'unsafe-eval' absent 1 per document load, all the same one (see Acceptance notes) 0

In 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-ancestors was absent only on the public form URL.

Acceptance notes

  • With OS_PAGE_REACT=off, each document load reports one script-src eval refusal from the Console bundle. The source is zod v4's capability probe: it tries Function('') 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's jitless config is set, so the clean fix is objectui-side: set z.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'.
  • Monaco. The code editor's CDN load is refused by design, as above. Self-hosting Monaco in objectui would restore the full editor under this policy.
  • Out of scope. Where the Console keeps its session token is a separate decision, and this PR does not change it.

Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_013zqbSrrxA8RC7X5JQ4VHLV

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/cli, touching 17 documentable anchor(s).

3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/deployment/environment-variables.mdx (via OS_CONSOLE_CSP_CONNECT_SRC (literal, a string literal in CONSOLE_CSP_CONNECT_SRC_ENV), /api/v1/runtime/config (route, a path literal in a comment on a changed line))
  • content/docs/ui/forms.mdx (via /forms/:slug (route, a path literal in a comment on a changed line))
  • content/docs/ui/public-data-collection.mdx (via /forms/:slug (route, a path literal in a comment on a changed line))

⛔ 2 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-6.mdx (via /forms/:slug (route, a path literal in a comment on a changed line))
  • content/docs/releases/v17/17-7.mdx (via /forms/:slug (route, a path literal in a comment on a changed line))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 54 of 206 client-bound route-ledger rows — the other 152 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 152: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 97 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 30 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 9c43e19f659c40bb065601bda50c7e05250169f2 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 6d9649ac84c9684896b9355e66e7c29c6d0c21ba — the merge of head e6d0e56d51d32bb32756c0f8f1cea85c7ad448a9 into base 9c43e19f659c40bb065601bda50c7e05250169f2, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# 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

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 9c43e19f659c40bb065601bda50c7e05250169f2 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@os-tesla
os-tesla marked this pull request as ready for review October 25, 2026 09:18
@os-tesla
os-tesla enabled auto-merge October 25, 2026 09:19
@os-tesla
os-tesla added this pull request to the merge queue Oct 25, 2026
Merged via the queue into main with commit 3c30afd Oct 25, 2026
43 checks passed
@os-tesla
os-tesla deleted the claude/project-thread-9xn5vl branch October 25, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants