Skip to content

Let a Leaf page frame another live Leaf page on the same machine - #5035

Merged
max-sixty merged 5 commits into
mainfrom
grind/issue-5008
Nov 3, 2026
Merged

max-sixty merged 5 commits into
mainfrom
grind/issue-5008

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

A Leaf page can now show another Leaf page from the same machine in an <iframe>. Before, page a's frame of page b stayed empty, because every served document carried frame-ancestors 'self' and the two pages run on two leaf server ports.

Closes #5008

For Max

This moves a trust boundary, and you chose to land it. After this change, any live Leaf page's scripts can frame every other live page under the same state home and dress its decisions in a different interface. That includes third-party scripts a page loads, such as a charting library from a CDN. The key cookie already reached every port on the host, so such a script's requests to b already carried it; what's new is that the script can show b's live controls inside its own page and cover them. Before, only b's own origin could do that. The case for it is that every page under the state home is the same user's, written by their agents, and already reachable with the same key. The cost is that a page's third-party scripts, trusted with that page, can now frame every live page.

What changed

A page's running server now adds to frame-ancestors the exact origin of every other Leaf server that holds its lease under the same state home (PageEndpoint._frame_ancestors, which reads presence.live_servers). Nothing is asked of page authors: a's source holds <iframe src="http://127.0.0.1:<b's port>/">, the bare address, and the key cookie from the user's arrival at a authorizes it.

  • The reading happens at each framed document, so a server started after b can frame it. A server whose lease has ended is left out, since its port may since belong to any process.
  • A top-level navigation (Sec-Fetch-Dest: document) has no ancestors to admit and skips the reading, so ordinary page loads pay nothing.
  • A temporary server (--lifetime temporary), which has its own key and keeps no service record or row, and leaf.page still send frame-ancestors 'self' alone.
  • A server at a bare IPv6 address is left out of the list. CSP's source grammar has no IPv6 literal, and Chromium logs such a source as an error on every framed document, so a page served at one can't frame another.
  • page check --render answers a frame of each other live Leaf page with a stand-in page ("Another Leaf page, checked on its own."), since its browser holds no key for that page and that page's server refuses the gate's origin as a framer (render_gate.scheme.stand_in_other_leaves). Without it, every framing page failed the check with a 401 console error its author couldn't fix, whose text pointed toward putting the key in the src. Only a child frame's navigation stands in: a script, stylesheet, image or fetch() the framing page loads from that server reaches the server as it would without the stand-in. A frame of any other address, a mistyped port included, still loads and fails.
  • live_leaves (the others menu and page list) now reads the same live_servers walk. server.page_origin is the one spelling of a page's origin; page_url and TemporaryPageServer.origin build on it.
  • The sample-child exemption is now "never set the header" rather than "delete it afterwards", so a widened policy can't reach a sample child.
  • validation.md's "Delivery policy" states the rule, and "Browser validation" the stand-in. "Delivery policy" also claimed sample children carry the header, which they haven't since Contain Leaf sample navigation while preserving native delivery #2255.
  • live-samples.md, which told authors a served page frames only inside its own origin, now says a page may frame another live Leaf page by its address without the ?t= key, and that the render check shows a stand-in there.
  • The comment in browser/runtime/frame-visibility.js that said a framed Leaf document always has a same-origin parent now describes the cross-port case. That comment edit changes the runtime's source hash, so dist/kernel/kernel.json is rebuilt; no bundle changed.

Security argument

  • The key cookie already reaches every port. Cookies are scoped by host, not port, so the host-key cookie (SameSite=Strict, HttpOnly) is sent to every server on the page's host, Leaf or not, and a frame from another port is same-site. The browser test shows it: a frame request from another server's page at another port carries the key cookie. frame-ancestors is the only defence against another local server framing a live page and dressing its decisions in a different interface.
  • Admitting same-key Leaf servers exposes no new key. Every server that publishes a row in the state home serves with that state home's key (server.host_key). That key already authorizes a bare link to each of them, and the others menu links them. The framing ability itself is new, and "For Max" above says what it admits.
  • Getting listed takes the user's own access. A listed origin needs a row in the state home (mode 0700) and a held server lease beside an enabled service.json. Only a process running as the user can arrange that, and such a process can already read the key from access.json.
  • No wildcard. http://127.0.0.1:* would admit any local web server, such as a dev server on :3000, to frame a live page with the user's key cookie. The policy lists exact origins instead.
  • Only live leases count. The origins come from server.running_server, which requires the server lease to be held and to name the recorded incarnation. A stale row or service.json for a stopped server admits nothing, so a foreign process that later binds a dead Leaf server's port can't frame. The list is read when each framed document is served; a back/forward cache restore could carry a list read before a framer stopped (an untested hypothesis).
  • --host. A server started with --host NAME is listed as http://NAME:<port>, the origin its URL names. Two pages served under the same name share a host, so the frame is same-site and the cookie flows into it as on loopback. The repro passes with both pages under --host localhost; a tailnet name wasn't tried.

An independent review tried a missing or forged Sec-Fetch-Dest (only ever yields the full list), a framer killed with kill -9 ('self' on the next request), a plain http.server on the dead framer's port (refused although the cookie reaches b), temporary and other-state-home servers (excluded), and leaf.page (unchanged).

Evidence

The issue's steps, scripted against a scratch XDG_STATE_HOME with each page's server started by leaf server start --lifetime persistent and b's bare address in a's <iframe>:

  • Before: b's policy was frame-ancestors 'self', the frame stayed empty, and Chromium logged Framing 'http://127.0.0.1:59935/' violates the following Content Security Policy directive: "frame-ancestors 'self'".
  • After: b's policy is frame-ancestors 'self' http://127.0.0.1:65327 (a's origin). The frame shows b's heading, with no console messages. leaf page check --render a passes, and its screens show the stand-in in the frame.
  • With --lifetime temporary, as the issue's steps run, both before and after are refused. Each temporary server has a key of its own, so its src must carry the key, and it keeps no record for another server to find. The fix applies to server start and server run with the session or persistent lifetime, and to leaf-dev preview --user.

Cost, on a real persistent server beside 80 fake live neighbours (this Mac's state home had 80 live servers at the time), 60 requests each:

median p90 policy
top-level document, 0 neighbours 1.77 ms 2.08 ms 22 B
top-level document, 80 neighbours 1.92 ms 2.52 ms 22 B
framed document, 80 neighbours 8.49 ms 10.05 ms 1862 B

Each live neighbour costs a framed document about 75 µs (a lease probe and two record reads).

A framed page, in Chromium and Firefox

Driven with Playwright, a framing b (900×640) with an lf-options ask in b:

  • Works: b presents. Picking an option in the frame lands in b's log. A page comment typed in b's panel lands in b's log and opens its thread in b's panel, which sits inside the frame while a's panel stays at the window's foot. Keys follow focus: after a click in the frame ? opens b's keyboard reference, and after a click in a it opens a's. localStorage, where drafts live, is shared between the framed b and b in a tab of its own.
  • Differs: b can't read a's frame element across origins, so it counts itself shown whenever its tab is, even scrolled out of a's view (frameVisibility() is null on screen and scrolled away). A same-origin frame reads its frame element instead.
  • Differs: b reports the frame's viewport (900×640) as the user's window, so while that is its newest report, b's page check --render lays b out at the frame's size.

Tests

  • tests/process/test_interact_server.py::test_a_page_admits_frames_only_from_live_leaf_servers_under_its_key: a real persistent server's document names a live neighbour's origin exactly, and leaves out a neighbour whose server stopped. A mutation that read records without checking the leases failed it.
  • tests/browser/startup/test_hosting.py::test_a_live_page_admits_only_leaf_parents_under_its_key replaces test_a_live_page_refuses_a_same_site_parent_at_another_port. One live child page is framed by another server's page at another port, which is refused although its frame request carries the key cookie, and by another live Leaf page, where it presents. That other server is a temporary Leaf server, standing in for any server on the host outside the live set. On main's http.py the second frame is refused.
  • tests/browser/test_render_gate.py::test_a_frame_of_another_live_leaf_page_is_checked_on_its_own: a page framing a live Leaf page and a temporary server's page fails the gate only for the second. With the stand-in disabled, it also fails for the first's 401. On a page with the stand-in installed, a fetch() to the live server gets that server's 401 while the frame beside it shows the stand-in; when the stand-in answered every request to the origin (5d5a3b4), the fetch got its 200.
  • Ran on the current head: those three; the process and model tests that read neighbour rows, the CSP header or page_url (neighbour discovery and rows, the served state schema, sample capabilities, the website's routes, page list, a network-facing bind, the IPv6 address); by node id, the two neighbour-row tests and the end-to-end page check --render test that now live in tests/journeys/; the two All pages browser tests in test_render_controls.py that serve a live neighbour; the render gate test of a refused document and the hosting test of same-origin embedding; pnpm run test:runtime (750 passed), pnpm run check, and pre-commit on the changed files.
  • Not run: the nightly tests/journeys/test_interact_server.py::test_server_round_trip, whose 'self' assertion is on a temporary server and so unchanged; WebKit beyond a CSP grammar probe.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 3 commits November 1, 2026 16:01
Two pages on one machine run on two `leaf server` ports, and every served
document carried `frame-ancestors 'self'`, so page a's `<iframe src="b's URL">`
stayed empty with Chromium logging the refusal.

A page's running server now adds to that policy the exact origin of every other
Leaf server that holds its lease under the same state home
(`PageEndpoint._frame_ancestors`, reading `presence.live_servers`). Those
servers all serve with the state home's key (`server.host_key`), whose cookie
already authorizes a bare link to each of them, so a framing page exposes
nothing the key doesn't. The reading happens at each framed document, so a
server started after the framed one is admitted; a server whose lease has
ended is not, since its port may since belong to any process. A top-level
navigation (`Sec-Fetch-Dest: document`) has no ancestors and skips the
reading. A temporary server, with its own key and no record, and leaf.page
keep `'self'` alone.

`live_leaves` now reads the same `live_servers` walk, and `server.page_origin`
is the one spelling of a page's origin, which `page_url` builds on. The sample
child exemption moved from deleting the header afterwards to never setting it.
validation.md's "Delivery policy" states the rule; it also said sample children
carry the header, which they haven't since #2255.

Cost, on a real persistent server beside 80 fake live neighbours (this Mac had
80 live servers): a top-level document answers in 1.9 ms against 1.8 ms with
none; a framed one in 8.5 ms with an 1862-byte policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
live-samples.md said an ordinary served page appears in an `<iframe>` only
inside a page of the same origin. A page this machine serves may now frame
another, by the address `leaf page list` prints less its `?t=` key: the key
in the framing page's own address already set the cookie the frame goes out
under, and leaving it out keeps the key out of the page's source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`page check --render` refused every page framing another live Leaf page: its
browser holds no key for the framed page, so the frame answered 401 and the
gate counted the console error against the framing page, whose author can't
fix it. The error's text also steered an agent toward putting the key in the
frame's `src`, which leaks the key and still fails, since the framed page's
server refuses the gate's origin as a framer.

The gate now answers each other live Leaf origin with a stand-in document
("Another Leaf page, checked on its own.") in each page and context it opens
(`render_gate.scheme.stand_in_other_leaves`, one route matching the origins
`presence.live_servers` names). A frame of any other address still loads and
fails as before. `test_a_frame_of_another_live_leaf_page_is_checked_on_its_own`
frames a live Leaf page and a temporary server's page: the gate reports only
the second, and with the stand-in disabled it also reports the first's 401.
`page check --render` on a framing page now passes, its screens showing the
stand-in.

A server at a bare IPv6 address is left out of `frame-ancestors`: CSP's source
grammar has no IPv6 literal, and Chromium logs such a source as an error on
every framed document. `TemporaryPageServer.origin` spells its origin through
`server.page_origin`. validation.md and live-samples.md say what the gate shows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The render-check exemption currently reaches subresources as well as framed documents; the inline finding narrows it to the intended boundary.

Comment thread src/leaf/render_gate/scheme.py Resolved
`page check --render` answered every request under another live Leaf
server's origin with the stand-in page, so a script, stylesheet, image or
`fetch()` the framing page loaded from that server received HTML too. The
stand-in now answers only a child frame's navigation; every other request
falls back to its normal route and reaches the server, which refuses the
gate's keyless browser as it would without the stand-in.

The render gate test now also checks, on a page with the stand-in
installed, that a `fetch()` to the live server gets that server's 401
while the frame beside it shows the stand-in. On the previous head the
fetch received the stand-in's 200.
@max-sixty
max-sixty marked this pull request as ready for review November 3, 2026 05:04
@max-sixty
max-sixty merged commit 3cbb347 into main Nov 3, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/issue-5008 branch November 3, 2026 05:15
leaf-agent added a commit that referenced this pull request Nov 3, 2026
…pages (#5216)

The nightly guard
`test_the_resources_a_fixture_owns_are_taken_from_that_fixture` failed
because two tests closed a page they took from the `browser` fixture:
the floating-box journey (added in #5054), and
`test_a_frame_of_another_live_leaf_page_is_checked_on_its_own` in
`tests/browser/test_render_gate.py` (added in #5035; it fails the guard
on current main too). The fixture closes every context it lent at
teardown, after `judge_watches` reads each page that is still open.
Closing early skipped that reading for every Hypothesis example of the
journey. Both tests now leave their pages for the fixture to close, and
neither test's assertions change.

Verified locally: the guard failed on main naming both files and passes
now. The gate test passes. `tests/journeys/test_floating_box_motion.py`
passes on Chromium and Firefox with every example's page left open until
teardown (22 per engine, about 100 s, peak resident memory of the
largest single process 1.9 GB).

Closes #5172 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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.

Let a Leaf page frame another page served on the same machine

2 participants