This repository has been archived on 2026-06-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
master-ai/vibn-frontend/components/project/preview-frame-trust.ts

19 lines
570 B
TypeScript

"use client";
/** Parent validates preview iframe postMessage origins against declared iframe.src + app origin. */
export function previewFrameTrustsMessage(
evOrigin: string,
targetOrigin: string | null,
iframeSrcAttr: string | undefined,
): boolean {
if (typeof window === "undefined") return false;
if (evOrigin === window.location.origin) return true;
if (targetOrigin && evOrigin === targetOrigin) return true;
try {
if (iframeSrcAttr && evOrigin === new URL(iframeSrcAttr).origin) return true;
} catch {
/* ignore */
}
return false;
}