Repository navigation
fix(studio): play a preview its server sandboxed - #7815
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 103 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
miguel-heygen
left a comment
There was a problem hiding this comment.
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.
3674556 to
e7c7829
Compare
|
Independent verification at
No source edits were needed. Scope remains the requested |
There was a problem hiding this comment.
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 whilepreviewFrameOpaque(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
nullis dropped, and the new test asserts exactly that (fromFrame({}, …, "null")leaves time at 0). - the playback mirror looks up
-
No stale allowance.
frameOriginsis recomputed on every message, andpreviewFrameOpaquereads the live window. So once the frame goes back to a readable document,nullstops 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
nullpath feeds the same handlers as before:state,timelineandstage-sizeinto 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 runonpreviewChannel.test.ts,useElementPicker.test.tsandPlayer.test.tsgives 80 passed. WithbridgePlayback.tsset 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)
previewFrameOpaqueis true for any cross-origin frame, not only one sandboxed from its server, so a frame with a cross-originsrcalso getsnulladded. 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
left a comment
There was a problem hiding this comment.
Re-review at e7c78299, replacing my Changes Requested at 36745562. @jrusso1020 approved this head.
Earlier findings: addressed
- Rebased down to the
frameOriginschange. The diff isbridgePlayback.ts(+7/−1) and one test. - The
previewRequest/previewComputedStylesexports are gone, and the requiredBuildis green. - The merge is clean. The PR is based on
af0560c8, and nothing merged since then touchesplayer/lib/oruseElementPicker.ts.git merge-treeagainst currentmain(b650d0d1) comes back clean.
Why the extra null is safe
- Both callers accept a post only when
event.sourceis the frame's own window:- the playback mirror (
bridgePlayback.ts:130-131, wheremirrors.get(event.source)comes first); useElementPicker(useElementPicker.ts:221-228).
- the playback mirror (
nullis 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 extranulllets no new sender in.- The path for a frame whose
sandboxattribute lacksallow-same-originstill 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
nullfrom 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.sourcechecks.
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.
What
Studio now plays a preview that its server made opaque. A host can do this with
Content-Security-Policy: sandbox allow-scriptson the preview document, under a frame that has nosandboxattribute. That page posts asnull.frameOrigins(player/lib/bridgePlayback.ts) read the origin off the attribute and thesrc, so it expected the page's origin and dropped everystateandtimelinepost, and Play did nothing.frameOriginsnow also acceptsnullfor such a frame, but only while its window refuses reads (previewFrameOpaque). Its callers accept a post only whenevent.sourceis the frame's own window. A window posts as its own document's origin, so the extranulllets in only the opaque page loaded in that frame.frameOriginshas two callers: the playback mirror anduseElementPicker, which checksevent.sourcethe same way.The
Player/NLEPreviewsandboxOriginprop and thepreviewFrameOpaqueexport shipped in #7811 and #7817, so they were dropped from this PR, along with thepreviewRequest/previewComputedStylesexports.Test plan
On macOS,
packages/studio, rebased onmainat af0560c:vitest run src/player/lib/previewChannel.test.ts src/hooks/useElementPicker.test.ts src/player/components/Player.test.ts: 80 passed.sandboxattribute whose window refuses reads ignores astatefrom its own window with another origin, and anullone from a different window. It takes anullone from its own window.bridgePlayback.tsset back tomain, that test fails (1 failed, 15 passed).tsc --noEmitis clean, and so areoxlintandoxfmt --checkon 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
sandboxattribute, soframeOriginsreturns 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, nosandboxattribute) is affected: its Play now runs instead of doing nothing. The change is 7 lines inbridgePlayback.tsplus a test.