diff --git a/packages/live-preview-sdk/src/constants.ts b/packages/live-preview-sdk/src/constants.ts index 70657b26..efd12c4d 100644 --- a/packages/live-preview-sdk/src/constants.ts +++ b/packages/live-preview-sdk/src/constants.ts @@ -12,3 +12,5 @@ export const MAX_DEPTH = 10; export const LIVE_PREVIEW_EDITOR_SOURCE = 'live-preview-editor' as const; export const LIVE_PREVIEW_SDK_SOURCE = 'live-preview-sdk' as const; + +export const CONTENTFUL_ORIGINS = ['https://app.contentful.com', 'https://app.eu.contentful.com']; diff --git a/packages/live-preview-sdk/src/helpers/utils.ts b/packages/live-preview-sdk/src/helpers/utils.ts index b7b4feff..c4023c41 100644 --- a/packages/live-preview-sdk/src/helpers/utils.ts +++ b/packages/live-preview-sdk/src/helpers/utils.ts @@ -1,5 +1,5 @@ import * as packageJson from '../../package.json'; -import { LIVE_PREVIEW_SDK_SOURCE } from '../constants'; +import { CONTENTFUL_ORIGINS, LIVE_PREVIEW_SDK_SOURCE } from '../constants'; import { PostMessageMethods } from '../messages'; import type { EditorMessage, MessageFromSDK } from '../messages'; import { debug } from './debug'; @@ -20,10 +20,9 @@ export function sendMessageToEditor(method: PostMessageMethods, data: EditorMess debug.log('Send message', message); - window.top?.postMessage( - message, - '*' // TODO: check if there is any security risk with this - ); + CONTENTFUL_ORIGINS.forEach((origin) => { + window.top?.postMessage(message, origin); + }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any