Repository navigation
fix(studio-server): thumbnail origin from the server, sandbox previews from other sites - #7492
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 88 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
There was a problem hiding this comment.
Verdict: APPROVE · 0 blocker · 0 important · 0 nits · f9065fb
The required CI passed at this head (CI, Windows tests/render, captures, regression, CodeQL).
Scope
I read the full diff. createStudioServer has a single caller (runEmbeddedMode), and it always supplies origin, so the loopback-Host 400 fallback only applies before the server is listening or in in-process requests. The Vite adapter now reports serverOrigin for its own generateThumbnail. Nothing under studio-server sets a CSP that the new middleware would overwrite. Hono re-wraps a finalized response before c.header, so the post-next() header write is safe. I also checked a downstream consumer: HFI desktop already sandboxes opaque previews and refuses foreign /preview work with its own middleware, so this change doesn't affect desktop until it bumps the package. It also doesn't conflict with desktop's frame-ancestors, which is only set on renderer files. I didn't run the Vite dev host end to end. The approval covers f9065fb only; if #7490 lands first, the rebased head needs fresh CI.
— Genesis
jerrai-bot-heygen
left a comment
There was a problem hiding this comment.
Findings-only review at f9065fb: no demonstrated blocker in the built-in CLI/Vite thumbnail-origin fix or the normal Studio/render/snapshot paths. Both thumbnail adapters supply the listening origin; the cross-site/same-site CSP is mounted only on Studio API preview documents. Studio's same-origin iframe stays unsandboxed by this response, and hyperframes snapshot and producer renders use their own file servers rather than that middleware. Hosted exact-head CLI/studio-server tests executed (including thumbnail-origin, sandbox and origin helper cases). Compatibility boundary: an externally embedded preview is different: sandbox allow-scripts gives its document an opaque origin. Relative URLs still resolve, and ordinary scripts/images/media may run/display, but local @font-face, ES modules, and fetch() of local assets can fail CORS; the preview asset responses do not add CORS permission. Current fixtures prove header routing, not faithful rendering of those asset classes. This is a consequence of the intended isolation, not proof of a security bypass; document/test it if external preview fidelity is a product requirement. #7490's separate public-editor Host allowlist requirement remains for Cut Room on a CLI upgrade, and the combined tree needs fresh review after either PR rebases. No approval, merge, or live render by me. — Jerrai
…s from other sites The thumbnail route builds the headless browser's URL from the server's own listening origin (a new optional `serverOrigin` on the adapter, wired in the CLI preview server and the Vite dev host) instead of the request's Host header. Hosts that report no origin fall back to a loopback Host only. Preview responses (bundled, sub-composition and project files) opened from another site carry `Content-Security-Policy: sandbox allow-scripts` and `Vary: Sec-Fetch-Site`. Studio's same-origin iframe, browser automation and non-browser clients are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f9065fb to
d1fc1d3
Compare
With HYPERFRAMES_PREVIEW_HOST set to a hostname, the listening address is the IP it resolved to, and the Host check accepts the bind name, not that IP. The thumbnail browser then loaded a 403 page. Use the bind name when it is a hostname; IP and wildcard binds keep the listening address. — Rames Jusso Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kage's comment share The hostname-bind rule is stated by its test name in serverOrigin.test.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adapt upstream heygen-com#7492 and preserve existing content security policies.
What
The thumbnail route now builds the headless browser's URL from the server's own listening origin instead of the request's
Hostheader, and project HTML/SVG served by the preview routes is sent with asandboxCSP when it is opened from another site. Studio's own iframe, browser automation and CLI clients see no change.Why
Hardening for the local preview server: the URL the thumbnail browser navigates to should not depend on a request header, and project documents opened from another site should not run with the API's origin.
Related work
Refs #7490 (which carries #6128 forward). That PR handles the write-side origin and host checks; this one does not touch them.
How
See the collapsed write-up below.
Test plan
No visible change
The only change under
packages/studiois six lines invite.adapter.tsthat report the dev server's own origin to the thumbnail route. Studio renders and plays the same; the headless-Chrome check in the write-up below loads a composition in Studio's iframe and plays it on this branch.Claude Opus 5.5
What changed
Thumbnail navigation target
StudioApiAdaptergains an optionalserverOrigin(). The thumbnail route uses it forpreviewUrl. When a host does not provide it (or it returns nothing yet), the route accepts theHostheader only if the whole header is a loopback name (localhost,127.x.x.x,[::1], optional port, nothing after it), and otherwise answers 400 without callinggenerateThumbnail. An in-process request with noHostat all (tests,app.request) keeps usinghttp://localhost.originForListeningAddress(server.address())in@hyperframes/studio-server: an unspecified bind (0.0.0.0,::) maps to127.0.0.1, IPv6 literals are bracketed.hyperframes preview:listening(already passed tocreateStudioServerasoriginfor the history owner URL) is now derived from the bound address rather than hard-coded127.0.0.1, and the adapter exposes it asserverOrigin. Default and0.0.0.0binds produce the samehttp://127.0.0.1:<port>as before; aHYPERFRAMES_PREVIEW_HOSTbound to one specific address now gets that address, which is the one Chrome can actually reach.packages/studio/vite.adapter.ts):serverOriginfromserver.httpServer.address().Preview sandbox
/projects/:id/preview/*increateStudioApi(Hono's/*also matches the bare/preview, so it covers the bundled preview,/preview/comp/*and the project-file route). It always appendsVary: Sec-Fetch-Site, and addsContent-Security-Policy: sandbox allow-scripts(noallow-same-origin) whenSec-Fetch-Siteiscross-siteorsame-site.same-origin,noneand an absent header are unchanged.Varymatters because the bundled and sub-composition previews areprivate, no-cachewith an ETag: without it a response cached in one context could be revalidated in the other and carry or drop the CSP. Project HTML/SVG files are alreadyno-store.Routes checked for the same issue
/files/*,/gsap-animations/*) or fixed non-document types (render outputs: mp4/webm/mov/gif; fonts:font/*as attachment; thumbnails: jpeg/png). The CLI's own static routes serve the Studio bundle and GSAP vendor files, not project files.serveStaticProjectHtml(used bycheck,snapshot,compare) serves project files on a random-port, loopback-only, short-lived server that has no Studio API, so it is left as is.Sec-Fetch-Site: same-origin,Sec-Fetch-Dest: iframe. Puppeteerpage.goto(thumbnails, capture) sendsnone; Nodefetch(prebuild) sends nothing.What I measured
Unit tests (drive the real route handlers)
src/routes/thumbnail.origin.test.ts(3): a foreignHostwithserverOriginset navigates tohttp://127.0.0.1:3002/api/projects/demo/preview?...; withoutserverOrigin, four non-loopback Host shapes (including127.0.0.1:3002@other.exampleand127.0.0.1.other.example:3002) get 400 and the adapter is never called; loopback Hosts pass through as given.src/routes/preview.sandbox.test.ts(21): throughcreateStudioApi, for a project.html, a project.svg, the bundled preview and a sub-composition preview,cross-siteandsame-siteget the sandbox CSP;same-origin,noneand no header do not; all carryVary: Sec-Fetch-Site, including a 304.src/helpers/serverOrigin.test.ts(6) and one CLI test thatcreateStudioServer's adapter reports theoriginoption asserverOrigin.Varyassertion. The helper test file cannot import on main.studio-server95 files, 1682 passed, 2 skipped. CLIsrc/server/plus the preview command tests: all pass (one existing mock inpreview.startFailure.test.tsneeded the new export). Studiovite.adapter*/vite.studio-server-module/vite.configtests: 38 passed.tsc --noEmitfor studio-server, cli and studio; rootbun run lint;oxfmt --check;check-comment-citationsandcomment-ratchetagainst the merge-base: all clean.Real path (built CLI,
hyperframes previewon a scaffolded project, a logging HTTP listener on 127.0.0.1:3699 standing in for another local service)curl -H 'Host: other.example:3612' .../api/projects/demo/thumbnail/index.html?t=1: main returns 500 (Chrome tried to loadother.example); this branch returns 200, a 240x135 JPEG of the composition.curl -H 'Host: localhost:3699' .../thumbnail/index.html?t=1.5: on main the listener loggedGET /api/projects/demo/preview?hf-capture=1 host=localhost:3699; on this branch it logged no request and the thumbnail is the real composition (same 2956 bytes as above).curl -H 'Sec-Fetch-Site: cross-site' .../preview/page.html:content-security-policy: sandbox allow-scripts,vary: Sec-Fetch-Site(same forsame-site, an.svg, and the bundled/preview). Withsame-origin,noneor no header: no CSP. Main: no CSP in any case.http://127.0.0.1:3612/loads the composition in its iframe (response has no CSP), the parent readsiframe.contentWindow(originhttp://127.0.0.1:3612, 6 timelines), and Space plays it (player time 0 to 2.02 s in 2 s). A page onhttp://localhost:3699framingpage.html, and the same page navigated top-level from there: the document's scripts run,window.originis"null", and a fetch of/api/projectsfails. Openingpage.htmldirectly (address bar,Sec-Fetch-Site: none): originhttp://127.0.0.1:3612, fetch 200.What I did NOT exercise
bun run studio) end to end: itsserverOriginis typechecked and its existing tests pass, but I did not request a thumbnail through a running dev server.HYPERFRAMES_PREVIEW_HOSTbound to a specific LAN address, IPv6-only binds, and anhttpsVite server: covered by the helper's unit cases only.Sec-Fetch-Siteis sent by current Chromium, Firefox and Safari; an older browser that omits it is treated like a non-browser client and gets no CSP.same-origin, but I did not run it.createStudioApi.ts,studioServer.ts,studioServer.test.tsandindex.ts; whichever lands second may need a small rebase.— Rames Jusso
🤖 Generated with Claude Code