mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(studio): take playback posts from a preview its server sandboxed (#7815)
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.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// because a runtime posts its first `timeline` while it boots.
|
||||
import type { PlaybackAdapter } from "./playbackTypes";
|
||||
import { inspectStudioRuntimeMessage, postRuntimeControlMessage } from "./runtimeProtocol";
|
||||
import { previewFrameOpaque } from "./previewChannel";
|
||||
|
||||
interface PlaybackMirror {
|
||||
iframe: HTMLIFrameElement;
|
||||
@@ -56,10 +57,15 @@ export function previewStageSize(
|
||||
return (frame && mirrors.get(frame)?.stageSize) ?? null;
|
||||
}
|
||||
|
||||
/** The origins a post from this frame can carry, given its sandbox and what it loads. */
|
||||
/** The origins a post from this frame can carry; a page its server sandboxed posts as `null` without the attribute. */
|
||||
export function frameOrigins(iframe: HTMLIFrameElement): string[] {
|
||||
const sandbox = iframe.getAttribute("sandbox")?.toLowerCase().split(/\s+/);
|
||||
if (sandbox && !sandbox.includes("allow-same-origin")) return ["null"];
|
||||
const loaded = loadedOrigins(iframe);
|
||||
return previewFrameOpaque(iframe) && !loaded.includes("null") ? [...loaded, "null"] : loaded;
|
||||
}
|
||||
|
||||
function loadedOrigins(iframe: HTMLIFrameElement): string[] {
|
||||
const src = iframe.getAttribute("src");
|
||||
if (iframe.hasAttribute("srcdoc") || !src) return [window.location.origin];
|
||||
try {
|
||||
|
||||
@@ -219,6 +219,19 @@ describe("bridge playback for a frame Studio cannot script", () => {
|
||||
expect(own.getTime()).toBe(5);
|
||||
});
|
||||
|
||||
it("accepts a frame its server sandboxed, which posts as null though its frame has no sandbox", () => {
|
||||
const { iframe, frame } = opaqueFrame();
|
||||
iframe.removeAttribute("sandbox");
|
||||
iframe.setAttribute("src", "/api/projects/demo/preview");
|
||||
watchPreviewFrame(iframe);
|
||||
const adapter = bridgePlaybackAdapter(iframe)!;
|
||||
fromFrame(frame, { type: "state", currentTime: 6, isPlaying: false }, "https://example.com");
|
||||
fromFrame({}, { type: "state", currentTime: 7, isPlaying: false }, "null");
|
||||
expect(adapter.getTime()).toBe(0);
|
||||
fromFrame(frame, { type: "state", currentTime: 6, isPlaying: false }, "null");
|
||||
expect(adapter.getTime()).toBe(6);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["srcdoc", (f: HTMLIFrameElement) => f.setAttribute("srcdoc", "<p>x</p>"), location.origin],
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user