Repository navigation
Drop the page content policy; keep only the framing header - #1456
Conversation
…eep markup from refreshing the page elsewhere The served page and the export each wrote their own CSP, and they had drifted apart in ways nobody chose. Served pages allowed `'unsafe-eval'` (added in #782 for Playwright's wait polls); exports refused it, and WebAssembly with it. So a library that compiles at run time drew in a developer's preview and failed in the user's export. `build/browser/shipped.mjs` guarded against that by refusing any committed bundle that mentions `eval` or `Function`, even in unreachable code, which is why d3-dsv's `csvParseRows` and Vega were ruled out. The export's `script-src data:` also let any string become a running `<script src="data:…">`, nonce or not. `structure.page_policy(nonce, origin)` is now the one policy. Both deliveries call it, and they differ only in where the page's own files come from: `'self'` when served, nothing in an export. What changes: - Author code may compile in the export too: eval, `Function`, WebAssembly. - A blob: worker, blob: image or media, and a data: font or media now load on both, where the served page refused them. They admit no new origin. - The runtime entry and every authored script, inline or `src`, carry the delivery's nonce, and every module they import inherits it. So the export drops `data:` from `script-src`, and a data: script element runs on neither delivery. - `shipped.mjs` keeps only the checks an export needs to resolve a module graph: no `import()`, no bare specifier, no `require`. - `<meta http-equiv=refresh>` is refused by `page check` and at message admission (not in the vocabulary contract re-vendoring reads), because the browser follows it wherever it is inserted. A refresh sent the page, with whatever its URL carried, to another origin with no click, bypassing every fetch rule the policy sets. What the policy still refuses: any script without the nonce, handler attributes, `javascript:` URLs, `<base>` and form escapes, framing by another site, and fetches, images, and frames from origins outside the CDN set. Tests: `test_served_and_exported_pages_run_under_one_policy` runs each allowance and each refusal from an authored module file on both deliveries. It fails on the base, where the served page refuses the blob: worker, and without the nonce on authored `src` scripts, which the export then refuses. The server round trip expects the nonce on the runtime entry, and the served-policy test reads images under `default-src`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`build/webawesome/setup.mjs` replaced the upstream `system` icon library with a sprite mutator because upstream fetches each icon as a data: URL, which the old served policy refused. The page policy now admits data: fetches on every delivery, so the upstream library draws as shipped. The override is gone, and `setup.mjs` with it, since all it did besides was import the theme. Both entries now import `theme.mjs` directly. Checked: a `wa-icon library="system"` draws its path when served in Chrome, and in an export in Chromium and WebKit, with no console errors. The bundles are rebuilt from the lock. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rom any https: origin `page check` and revision capture refused several things. Some refusals turned out to protect nothing; one guarded a real ordering, but refused far more than that ordering needs. - **Scripts.** Only `<script type="module">` with exactly that attribute passed. This was a leftover from before #580, when pages had no scripts. The real constraint is timing. The runtime holds the authored `<main>` as the page's baseline, and listens for errors, from the moment its module runs. A parser-blocking or `async` script can run before that, changing what Leaf reads as authored and throwing where `page check` never hears it. So a script may now be any kind that runs after the runtime: an inline module, a module file, or a classic file with `defer` (a UMD bundle from a CDN, for example), in document order with the modules after it. Data blocks such as `type="application/json"` pass, and so do attributes like `integrity`. `page check` refuses an inline classic, parser-blocking or `async` script, saying why; also a `nonce` and an import map, which delivery owns. - **What reloads the page.** The executable digest now covers every script element: each inline body, data blocks included, and each `src`, including a CDN URL no capture holds. So a revision that changes a CDN script's version or a data block opens a fresh document instead of patching in place around code that already ran. A CDN module `src` had the same gap before. - **Computed `import()`.** Capture refused any `import()` whose argument was not a string literal. It now binds when it runs, which reaches a CDN module named by its full URL. A page file still needs a literal import: page files are served under the revision root, where a computed path does not reach. - **Content the page shows.** Images, audio and video, frames, fonts, and stylesheets may come from any https: URL, in capture and in `page_policy`. Scripts, and whatever the page's code fetches, stay on the CDN list: data reaches a page through its `data/` sources, where the log and an export hold it. Refusing remote images defended against a beacon, not against exfiltration: the page's own code can already navigate anywhere. - **Stylesheet links** no longer need exactly `rel` and `href`, so `media` and `integrity` pass. Handler attributes and `javascript:` URLs stay refused, since the page policy would never run them; the refusal now says so. `leaf-dev corpus` copies each inline script with its own attributes rather than as a module. `page-authoring.md` and `validation.md` state the new boundary. No eval case covers these clauses. Tests: the one-policy browser test now also loads a deferred classic script file, shows an image from another origin, and has its fetch to that origin refused, on both deliveries. The document tests pin the https: boundary for images and CSS imports, and each refusal left at the script boundary. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…op Tailwind's play CDN A CSS framework that runs in the browser, such as Tailwind, builds its `<style>` in the head after the page loads and rewrites it as classes change. `page-sheets.js` narrowed only the sheets the delivered document stated, so the framework's reset reached Leaf's controls: Tailwind 3's took the font family of every chrome button. The narrowing now also watches the head, so a sheet a script adds there, and each rewrite of it (a new sheet every time), keeps off the controls the way the page's own stylesheet does. A sheet a module constructs and adopts is still left as written. `https://cdn.tailwindcss.com` leaves the CDN list. It serves only Tailwind 3's play script, which builds from the mutations it sees while the document parses, so it has to block the parser. With `defer` it builds only when something later happens to mutate the page, which in the probe was one run in three. Tailwind 4's browser build on jsdelivr (`<script defer src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4">`) built in three runs of three and leaves the chrome's face alone. Tests: `test_a_sheet_a_page_script_writes_later_leaves_the_layers_controls_alone` writes and rewrites a head sheet from a page module, and fails without the watch. The external-origins test loads Tailwind 4 from jsdelivr instead. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A Leaf page is its author's code, and the author is the user's own agent, so a content policy on the page was guarding the page against its author. What it blocked was ordinary web development: scripts and modules from any server but six CDNs, fetches to any API, images and frames from other servers, inline handlers, and JSX through in-browser Babel, whose compiled scripts carry no nonce. Keeping it cost a nonce minted and threaded through every delivery, an export that needed its own policy, a validator repeating the policy's refusals, and a CDN list that capture, the policy and the MCP App all read. Removed: - `page_policy`, the served and exported `<meta>` policies, and every nonce, so `Delivery` carries no policy and its runtime script is a plain string. - `EXTERNAL_ORIGINS`. Capture leaves any http(s) or protocol-relative URL as written (`remote_reference`), for scripts and modules as for images. - `page check`'s refusals of handler attributes, `javascript:` URLs, and a script `nonce`, and the parser's tracking behind them. Handlers now run in a page and in message markup alike: both are the agent's. Kept, each for one reason: - `frame-ancestors 'none'` on every served page: no other site may frame a live page and take a click meant for one of its decisions. - A page's files stay in its directory: capture refuses a path or symlink that escapes it, so a revision never carries another file on the disk. - `X-Content-Type-Options: nosniff`, so a data route never runs as a script. The policy also neutralized markup that declares something about the whole document, which is a correctness problem rather than a trust one: a `<base>` sends the runtime's requests to another server, an http-equiv `<meta>` can navigate the page or block the runtime, and an authored import map leaves page modules unresolvable. One rule, `document_declaration_errors`, refuses all three in a page and at message admission, where a message would carry them into every revision. It sits beside the other admission gates, not in the vocabulary contract re-vendoring reads. The script-timing rule stays; it is about Leaf reading the page, not about trust. The MCP App's resource declares no resource domains, so a snapshot shown inside a host's own frame loads nothing from another server; a complete page runs in Leaf's frame and loads what it names. Tests: the policy tests go (the driver-poll allowance, base-uri and form-action refusals, the refresh-only refusal). The startup boundary test keeps framing and nosniff. The export test checks a deferred classic file and a module run the same served and exported, and that the module's image and fetch reach another server. Document tests pin the declaration rule and the http(s) boundary; a message test pins the rule at admission and that a handler passes; the site build test uses a `<base>` as its invalid document. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # tests/test_render_export.py
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The executable identity omits script attributes. Changing an inline <script type="application/json"> to <script type="module"> with the same body passed check_source and created a new revision in a local probe, but both revisions had the same executable digest. version.js then takes its in-place patch path instead of the reload path even though the page now has different executable code. The same gap applies to external script attributes. Include each script's attributes in the digest so an execution change gets a fresh document.
A script's type decides whether it runs and defer or async decide when, so a revision that turns a data block into a module, or changes an external script's attributes, needs a fresh document as much as one that changes its body. The digest now takes every script element whole: its attributes and its body's digest. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The digest still loses the order between inline and external scripts. Swapping an inline module with a deferred external script leaves both grouped lists unchanged, so version.js patches the standing document instead of reloading it. Chrome executes those two documents in different orders. The script sequence needs to follow document order before it is digested.
Scripts run in document order, so moving an inline script past an external one is new code as much as changing either. The executable digest took the two kinds as separate lists, which lost that order; it now takes every script by its place in the document. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # build/AGENTS.md # build/browser/build.test.mjs # build/browser/shipped.mjs # build/vendor.py # skills/leaf/scripts/leaf/exporting.py # skills/leaf/scripts/leaf/http.py
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Leaf's MCP Apps transport was an opt-in experiment. Codex's default handoff opens the page in its browser pane instead, and the experiment's own probe had stopped passing. It still had to follow every change to delivery, anchoring and the runtime. Every Codex install started `leaf mcp` and showed the model a `leaf_present` tool. Its comments-only snapshot was a second rendering of the page, which every thread and anchoring change also had to update. This removes the transport. A rebuild would start from the experiment's direct-resource design rather than from this code. ## Removed - `leaf mcp` and the Codex plugin's `mcpServers` registration. - `mcp_page.py`, `mcp_server.py`, `mcp_app.py` and `mcp-app.md`. - The `ui://` resource (`skills/leaf/mcp-app/`) and its build (`build/mcp-app/`, `build_mcp_app`). - The direct-resource probe and the experiment captures under `notes/mcp-apps/`. - The `mcp` Python dependency and the `@modelcontextprotocol/ext-apps` JS dependency, from both lockfiles and the browser build manifest. - The MCP tests, the `page_server` fixture and `run_async`. ## Code that existed only for it - **Event admission** no longer re-captures a comment's anchor from the file (`capture_anchors`). No remaining writer asked for that, since `leaf thread open` captures before it writes. `capture_anchor`'s prefix/suffix matching goes with it; its only caller was that re-capture. - **Export** drops `embedding`, `inline_css_assets` and `_file_reader`. It keeps its inliner, renamed `AssetInliner` because the delivery tests call it. - **Delivery** drops `Delivery.body_end` and `SourceDocument.body_close`. They existed only to inject the MCP page-ready script. - **The page server** no longer has an embeddable mode. `frame_ancestors_policy` is always sent, and a sample's `frame-ancestors 'self'` is now a class attribute on `SampleEndpoint`. ## Docs References, `AGENTS.md`, `build/AGENTS.md`, `scripts/AGENTS.md`, `validation.md`, `events.md`, `TODO.md` and the notes are updated to match. `notes/mcp-apps/PROJECT.md` now records: - what experiment 56 found; - why the probe broke; - how to restore the old code from `a8ed55e68`; - what to confirm before rebuilding. `TODO.md` keeps one entry to rebuild it. ## Tests `wt hook pre-merge` passed locally before main was merged in. That covers 1418 tests plus the browser and worker gates. The merge conflicts with #1456, which touched the deleted MCP files and the frame-policy comment, are resolved by keeping the deletions and taking main's text. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
A Leaf page's code is its author's, and the author is the user's own agent, so a content policy on the page guarded the page against its author. It blocked ordinary web development: WebAssembly in exports, blob: workers and images, scripts from anything but six CDNs, fetches to any API, images and frames from other servers, classic script files, computed
import(), and JSX through in-browser Babel. Keeping it cost a nonce threaded through every delivery, a second policy for exports, and validator rules restating the policy. This PR removes it and keeps three rules, each with one concrete reason:frame-ancestors 'none'on every served page, so no other site can frame a live page and take a click meant for one of its decisions.X-Content-Type-Options: nosniff, so a data route never runs as a script.What else changes
revision_delivery.py,http.py,exporting.py): no policy, no nonces;Delivery.runtimeis a plain string.EXTERNAL_ORIGINSis gone; capture leaves any http(s) or protocol-relative URL as written (structure.remote_reference).page check(validation/source.py,validation/markup.py): the handler,javascript:, nonce and CDN refusals go. Two correctness rules remain, neither about trust. A script must run after the runtime reads the page (a module, or a classic file withdefer), because an earlier one changes the authored baseline Leaf copies and throws where no check hears it. Anddocument_declaration_errorsrefuses a<base>, an http-equiv<meta>, or an import map in a page and at message admission, since each redirects the runtime's requests, navigates the page, or leaves modules unresolved, and a message would carry it into every revision.srcand data blocks, so changing one reloads the document instead of patching around code that already ran.runtime/page-sheets.js): the narrowing that keeps page CSS off Leaf's controls now also watches the head, so a CSS framework built in the browser (Tailwind 4 from jsdelivr works) leaves the chrome's face alone.build/webawesome/setup.mjsis gone.page-authoring.md,validation.md,mcp-app.md, and the Trust goal inAGENTS.mdstate the new contract.Testing
uv run pytest tests,npm run test:runtime, the browser checks, pre-commit and the bundle rebuild pass locally. The nightly-marked tests were not run locally at the user's request; this PR's CI runs them for the changed test files.test_an_export_runs_what_its_served_page_runsruns a deferred classic file and a module,eval, a blob: worker, a remote image and a remote fetch on both deliveries. New tests pin the declaration rule for pages and messages, the script-timing rule, and a script-written head sheet keeping off the chrome (it fails without the watch).🤖 Generated with Claude Code