Skip to content

fix(studio): play a preview its server sandboxed - #7815

Merged
xuanruli merged 1 commit into
mainfrom
fix/editor-preview-opaque-host
Nov 16, 2026
Merged

xuanruli merged 1 commit into
mainfrom
fix/editor-preview-opaque-host

Conversation

@xuanruli

@xuanruli xuanruli commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

Studio now plays a preview that its server made opaque. A host can do this with Content-Security-Policy: sandbox allow-scripts on the preview document, under a frame that has no sandbox attribute. That page posts as null. frameOrigins (player/lib/bridgePlayback.ts) read the origin off the attribute and the src, so it expected the page's origin and dropped every state and timeline post, and Play did nothing.

frameOrigins now also accepts null for such a frame, but only while its window refuses reads (previewFrameOpaque). Its callers accept a post only when event.source is the frame's own window. A window posts as its own document's origin, so the extra null lets in only the opaque page loaded in that frame.

frameOrigins has two callers: the playback mirror and useElementPicker, which checks event.source the same way.

The Player / NLEPreview sandboxOrigin prop and the previewFrameOpaque export shipped in #7811 and #7817, so they were dropped from this PR, along with the previewRequest / previewComputedStyles exports.

Test plan

On macOS, packages/studio, rebased on main at af0560c:

  • vitest run src/player/lib/previewChannel.test.ts src/hooks/useElementPicker.test.ts src/player/components/Player.test.ts: 80 passed.
  • New test: a frame with no sandbox attribute whose window refuses reads ignores a state from its own window with another origin, and a null one from a different window. It takes a null one from its own window.
  • With bridgePlayback.ts set back to main, that test fails (1 failed, 15 passed).
  • tsc --noEmit is clean, and so are oxlint and oxfmt --check on the two files.

Not re-run after the rebase: the manual check on a server-sandboxed editor preview. Before the rebase, Play ran with the change and never started without it. I did not run the element picker against such a preview.

No visible change

Studio as shipped frames its preview with a sandbox attribute, so frameOrigins returns what it did before and nothing on screen changes. Only a host that sandboxes the preview from its server (Content-Security-Policy: sandbox allow-scripts, no sandbox attribute) is affected: its Play now runs instead of doing nothing. The change is 7 lines in bridgePlayback.ts plus a test.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 103 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 (1)

  • seqrepeat-none-center-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo false, 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

@xuanruli xuanruli changed the title feat(studio): a host can frame the editor preview on an opaque origin feat(studio): a host can run the editor preview on an opaque origin and still drive it Nov 15, 2026
xuanruli added a commit that referenced this pull request Nov 15, 2026

@miguel-heygen miguel-heygen 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.

Reviewed at 3674556. Most of this already merged in #7811 and #7817 and ships in 0.9.54: Player and NLEPreview take sandboxOrigin and previewFrameOpaque is exported on main. The branch conflicts. After a rebase, keep only the frameOrigins change (sound: a null-origin post is accepted only from the frame's own window and only feeds the playback mirror). Drop the previewRequest / previewComputedStyles export: main's previewChannel no longer has them, so the build would break.

A preview made opaque by its server (Content-Security-Policy: sandbox) under a
frame with no sandbox attribute posts as null. frameOrigins now accepts null
for such a frame, only from that frame's own window and only while its window
refuses reads.
@xuanruli
xuanruli force-pushed the fix/editor-preview-opaque-host branch from 3674556 to e7c7829 Compare November 15, 2026 23:58
@xuanruli xuanruli changed the title feat(studio): a host can run the editor preview on an opaque origin and still drive it fix(studio): play a preview its server sandboxed Nov 15, 2026
@xuanruli

Copy link
Copy Markdown
Collaborator Author

Rebased on main and trimmed to the frameOrigins change and its test. The sandboxOrigin prop, the previewFrameOpaque export and the previewRequest / previewComputedStyles exports are gone, since #7811 and #7817 already cover them.

@xuanruli

Copy link
Copy Markdown
Collaborator Author

Independent verification at e7c78299d7d95379c79e9e9939f9e2fa703c82a7:

  • Traced both frameOrigins consumers: playback mirror's registered-window source lookup and useElementPicker's active/known-primary window guards. Readable same-origin frames retain their previous origin list; a cross-origin window refusing reads does not allow arbitrary origins or unrelated source windows.
  • 80 focused tests pass across previewChannel, useElementPicker, and Player. Restoring only bridgePlayback.ts to the parent revision makes the new regression fail (expected time 6, received 0; other 15 previewChannel tests pass).
  • Installed Chrome integration harness, bundling this head's bridge code: real HTTP Content-Security-Policy: sandbox allow-scripts, no iframe sandbox attribute, synthetic state/control responder. Final code receives time 6 then time 9 after play; parent code stays at 0. Navigating the same iframe to a readable same-origin document removes the extra null origin. This is browser integration evidence, not a full Studio UI/composition playback or element-picker browser walk.
  • Studio tsc --noEmit, changed-file oxlint, explicit repository-config oxfmt check, and diff whitespace check pass.

No source edits were needed. Scope remains the requested frameOrigins change and regression test.

@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 at e7c7829. Rebased as asked: the PR is now only the frameOrigins change plus one test, and the previewRequest / previewComputedStyles exports are gone.

What I checked

  • Source check. "null" is added only while previewFrameOpaque(iframe) is true, and both callers check the window before they look at the origin:

    • the playback mirror looks up mirrors.get(event.source) (bridgePlayback.ts:130-131);
    • the picker compares e.source === activeIframe.contentWindow, or uses its per-window map of swapped-out primaries (useElementPicker.ts:222-229).

    A post from any other window carrying null is dropped, and the new test asserts exactly that (fromFrame({}, …, "null") leaves time at 0).

  • No stale allowance. frameOrigins is recomputed on every message, and previewFrameOpaque reads the live window. So once the frame goes back to a readable document, null stops being accepted. The picker's swapped-out map is keyed by window, so it only ever covers the window that posted while it was primary.

  • No privilege gain. The null path feeds the same handlers as before:

    • state, timeline and stage-size into the playback mirror;
    • hover and pick into the picker.

    The document in that frame could already send those under its own origin, so this widens which origin is accepted from that one window, not who can post.

  • Test fails without the fix. At head, vitest run on previewChannel.test.ts, useElementPicker.test.ts and Player.test.ts gives 80 passed. With bridgePlayback.ts set back to the merge base af0560c and the new test kept, it gives 1 failed and 15 passed. The failing test is "accepts a frame its server sandboxed…", which matches the body.

  • CI. 42 pass and 39 skipped, with nothing failing or pending. The PR is mergeable.

Nits (non-blocking)

  • previewFrameOpaque is true for any cross-origin frame, not only one sandboxed from its server, so a frame with a cross-origin src also gets null added. That is harmless, because the same window check applies; the doc comment could just say "opaque or cross-origin".
  • No test covers the picker path with a server-sandboxed frame, and the body says it was not run manually. Its window check is the same shape as the mirror's, so this is fine to leave.

Gate: miguel-heygen's CHANGES_REQUESTED from 3674556 is still live, and this approval does not clear it. The rebase does what that review asked, so it needs his re-review or a dismissal.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low. Studio as shipped sets a sandbox attribute, so it takes the early return and nothing changes there. The only change is for hosts that sandbox the preview from the server.

Review by Rames

@miguel-heygen miguel-heygen 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.

Re-review at e7c78299, replacing my Changes Requested at 36745562. @jrusso1020 approved this head.

Earlier findings: addressed

  • Rebased down to the frameOrigins change. The diff is bridgePlayback.ts (+7/−1) and one test.
  • The previewRequest / previewComputedStyles exports are gone, and the required Build is green.
  • The merge is clean. The PR is based on af0560c8, and nothing merged since then touches player/lib/ or useElementPicker.ts. git merge-tree against current main (b650d0d1) comes back clean.

Why the extra null is safe

  • Both callers accept a post only when event.source is the frame's own window:
    • the playback mirror (bridgePlayback.ts:130-131, where mirrors.get(event.source) comes first);
    • useElementPicker (useElementPicker.ts:221-228).
  • null is added only while that window refuses reads (previewFrameOpaque, previewChannel.ts:15). A document in that window could already post as its own origin, so the extra null lets no new sender in.
  • The path for a frame whose sandbox attribute lacks allow-same-origin still returns ["null"] before the new code runs, so shipped Studio behaves exactly as before.
  • The new test covers both rejections: a wrong origin from the frame's own window, and null from a different window.

Nit

  • The manual Play check against a server-sandboxed preview wasn't re-run after the rebase (per the body). The picker wasn't run against such a preview either. Both are low risk given the two callers' event.source checks.

Not verified locally: I couldn't install the workspace in a scratch worktree, so I didn't re-run the vitest files or the revert check. I relied on the required Test job and the author's revert result (1 failed / 15 passed with bridgePlayback.ts at main).

CI: every required check on main's ruleset is green on this head. Studio and player captures shows one cancelled run from a superseded workflow run; the latest run of that job (133025036973) passed.

Verdict: APPROVE
Reasoning: The PR is down to the frameOrigins change I asked for. The added null only accepts posts from the frame's own window while that window is opaque, and every required check is green.

@xuanruli
xuanruli added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 1e54295 Nov 16, 2026
185 of 189 checks passed
@xuanruli
xuanruli deleted the fix/editor-preview-opaque-host branch November 16, 2026 01:35
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.

3 participants