Skip to content

fix: render and capture file servers answer only their own loopback host - #7853

Merged
michaelwang11394 merged 1 commit into
mainfrom
sec-loopback-host-1115
Nov 15, 2026
Merged

michaelwang11394 merged 1 commit into
mainfrom
sec-loopback-host-1115

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

The file servers that feed the capture browser now answer only their own loopback address, and they tell the browser that no other site may frame their pages.

  • serveStaticProjectHtml in the CLI serves the project for snapshot, check, validate, layout, compare, grade-compare and motion-shot.
  • createFileServer in the producer serves the project during hyperframes render, Studio renders and Desktop exports.
  • createFileServer in the engine is the smaller public version of the same server.

Why

Each server binds 127.0.0.1, but none of them checked the Host header. A website can point its own DNS name at 127.0.0.1 and then read these servers as if they were its own origin. That would let it fetch the project's page and files while a render or check is running. The served page also carries the HyperFrames runtime, which offers an editing channel to its parent frame. A page from another site could frame the server's page and use that channel.

A browser cannot forge the Host header, so checking it closes the first gap. Refusing cross-site framing closes the second.

Related work

Refs #7792, which added the Host rule for play and present.

How

  • A new engine helper, isOwnLoopbackHost, accepts only 127.0.0.1:<port>, localhost:<port> and [::1]:<port> for the port the server actually bound.
  • The producer and engine servers use a Hono middleware, answerOwnLoopbackHostOnly. It refuses any other Host with a 403 before a route opens a file. It also adds Content-Security-Policy: frame-ancestors 'self' and X-Frame-Options: SAMEORIGIN to every response.
  • The CLI server applies the same rule and the same headers in its node http handler. When a sandbox refuses listen(), the server answers in-process at a hyperframes-N.localhost origin. That path now sets its own Host on each request, and the server accepts that one name too.
  • The engine server applies the guard only when it is bound to a loopback address, which is its default. A caller that binds another interface has chosen to expose the server, so its behaviour is unchanged.
  • Every caller hands Chrome the URL the server returned (http://localhost:<port> or http://127.0.0.1:<port>), including Docker, Lambda, Cloud Run and distributed chunk workers, where Chrome runs next to the server. The public-only capture proxy sends the page server's host directly, so its Host is unchanged. No caller reaches these servers by another name.
  • Nothing frames these pages from another origin. Same-origin frames inside a composition still work.

The play, present and preview servers are not changed. They listen on every interface on purpose and keep their own wider Host rule.

Test plan

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

  • New tests for each server: a foreign Host gets 403 for /, /index.html and an asset; the server's own port answers on 127.0.0.1, localhost and [::1]; the HTML response carries both framing headers. These tests fail without the change.

  • Existing CLI server tests pass, including the in-process path and the Chromium range, charset and finding-inspector tests.

  • Existing producer file server tests pass, including scriptFailureAttribution.test.ts, which drives Chrome against createFileServer.

  • Ran hyperframes render, snapshot, check and validate from source on a sample project. All completed.

  • tsc --noEmit passes for engine, producer and cli.

…vers

The CLI static project server and the producer and engine file servers bind
127.0.0.1, but answered any Host header. They now refuse a request whose Host
is not 127.0.0.1, localhost or [::1] at their own port (or the in-process
origin the CLI hands out when listen is refused), and their responses carry
frame-ancestors 'self' and X-Frame-Options: SAMEORIGIN so another site cannot
frame the served page.
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 95 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (3)

  • seqrotatenudge-none-pct-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 3.03, render 0.04, renderKey -, undo false, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true
  • seqplainkeys-none-pct-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true
  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@jrusso1020 jrusso1020 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.

Approve. Reviewed at 2a7f35b2429b9f2af8fad11ccc937b2834aaed9c.

  • Host rule: all three capture file servers now answer only 127.0.0.1, localhost or [::1] on the port they actually bound.
  • Framing: every response says no other origin may frame it, so a foreign parent never gets the runtime's editing port.
  • In practice: every real caller still reaches the server by the exact host it was handed, and same-origin subframes keep working.

Nothing blocking.

Need: yes · Size: ok · Reuse: one loopbackOnly.ts helper shared by all three servers; studio-server's isLoopbackHost can't be imported from engine and has a different, any-port meaning for play/present · Simpler: already minimal · Structure: fine (checked studio-server request-identity and #7852's per-server copies; no split)
Risk: low. The only callers are local Chrome navigating to the URL the server returned, which passes the check by construction.

Overlap with #7852

#7852 and this PR fix the same two gaps on the same three servers, in different ways.

#7852 this PR
Host any loopback name, any port (studio-server isLoopbackHost in CLI/producer, a separate parser in engine, plus this machine's addresses on a wildcard bind) the three loopback names, own bound port only, one shared helper
Framing a <meta> mark that tells the runtime not to offer the editing port; CLI also sends CSP: sandbox to cross-site loads frame-ancestors 'self' + X-Frame-Options: SAMEORIGIN, enforced by the browser
Engine on 0.0.0.0 guarded; service-DNS callers get 403 unguarded (see nit 1)
  • They conflict. git merge-tree of both heads stops on packages/cli/src/utils/staticProjectServer.ts and packages/engine/src/services/fileServer.ts. Landing both would also leave two Host rules and two framing defences on each server.
  • I'd land this one and close #7852, or cut #7852 down to whatever it still adds. This one is stricter on Host (own port, no missing-Host fallback), uses one helper instead of two, and its framing defence doesn't depend on the runtime. It also avoids the service-DNS break on the exported engine server.
  • Does this one miss anything #7852 covers? I don't think so. The editing agent only answers window.parent (editingAgent.ts:143: if (parent === window || event.source !== parent) return;), and a top-level page is its own parent. So blocking foreign parents closes it, and #7852's mark adds nothing once that's in place.

Production path

  • Producer: createFileServer binds 127.0.0.1 and returns http://localhost:<boundPort>. listeningPort is set from the same boundPort before the promise resolves, including after settleOnBrowserSafePort re-settles. So the URL handed out always passes the own-port check.
  • Callers: probe, render, distributed chunk, frame-cost and reference-background stages each start their own server and navigate Chrome to its url.
  • Public-only capture proxy: browserProxyArgs(proxy.url, pageServerHost) bypasses exactly new URL(pageServerUrl).host. Chrome connects directly, with that host as Host.
  • hyperframes-internal: git grep -e createFileServer -e serveStaticProjectHtml -e fileServer.url on internal main returns 0 hits. Its producer server builds on the OSS render handlers, so this reaches prod renders on the next producer bump, with the same localhost URL.
  • CLI in-process fallback: answerInProcess now sets Host to the hyperframes-N.localhost name it handed out. listeningPort stays -1, so that one name is all it accepts.

Probes and tests

Real Chrome (headless shell 155, my own puppeteer harness, removed afterwards):

server top-level load same-origin /sub.html iframe framed by a page on another 127.0.0.1 port
CLI serveStaticProjectHtml 200, frame-ancestors 'self' loads (SUBPAGE) chrome-error://chromewebdata/
producer createFileServer 200 on http://localhost:<port>/index.html loads (SUBPAGE) chrome-error://chromewebdata/

At head:

  • engine fileServer.host + fileServer: 8/8 (vitest).
  • producer fileServer.host, file-race, listenError: 36/36 (vitest). Producer fileServer.test.ts: 65/65 (bun test).
  • CLI staticProjectServer + .host: 56 pass.
  • Two CLI browser tests gave no result here. range.chromium is env-gated and skipped. charset.browser timed out starting Chrome while this box sat at load 21, before it reached the server. The Chrome probe above covers that path.

Reverts and mutants:

  • All three server sources put back to the merge base: engine host 2/2 fail, producer host 4/8 fail, CLI host 4/7 fail.
  • answerInProcess without the forced Host: the in-process test fails. Node then sends Host: localhost, which has no port and is refused.
  • The Host check removed from answerOwnLoopbackHostOnly, framing headers kept: producer host 3/8 fail.

Nits (non-blocking)

  1. An engine server bound to a non-loopback address also loses the framing headers.
    • answerOwnLoopbackHostOnly sets both, so boundToLoopbackOnly === false skips framing as well as the Host rule.
    • Choosing to expose the server is a reason to skip the Host rule, not to let another site frame the page and take the editing port.
    • Fix: register a second small middleware that only sets SAME_ORIGIN_FRAMING_HEADERS, unconditionally, and keep the Host middleware behind the bind check.
    • No caller in this repo binds the engine server elsewhere today, so this only affects outside users of the export.
  2. [::1]:<port> is accepted, but the producer and CLI servers only bind 127.0.0.1. Harmless, since nothing can reach them on ::1. Say so in the helper's comment, or take the bound address as a parameter.
  3. Release note: an engine caller on 127.0.0.1 that reached the server as 127.0.0.2 or by a custom loopback alias now gets 403.

— Rames

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit f891a30 Nov 15, 2026
93 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-loopback-host-1115 branch November 15, 2026 18:29
miguel-heygen added a commit that referenced this pull request Nov 15, 2026
miguel-heygen added a commit that referenced this pull request Nov 15, 2026
daedal-ping Bot pushed a commit to DaedalGames/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.54

* chore: release v0.9.54 notes include heygen-com#7827, heygen-com#7825, heygen-com#7845, heygen-com#7848 and heygen-com#7849

* chore: release v0.9.54 notes include heygen-com#7853

* chore: release v0.9.54 notes include heygen-com#7851 and heygen-com#7855
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.

2 participants