From 0ad448b8a4255dc476fabe8281ee920d20c98de2 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 22 Mar 2026 00:24:24 +0100 Subject: [PATCH] enh: allow iframe postMessage prompts without same-origin (with HITL confirmation) (#22908) * Update Chat.svelte * Update Chat.svelte --- src/lib/components/chat/Chat.svelte | 36 +++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index d7374f898f..428f915a0a 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -569,11 +569,20 @@ origin: string; data: { type: string; text: string }; }) => { - if (event.origin !== window.origin) { + const isSameOrigin = event.origin === window.origin; + const type = event.data?.type; + + // Prompt-related message types only submit text to the chat input — + // functionally equivalent to the user typing. When same-origin is + // enabled they go through immediately. When it is disabled (opaque + // origin) we show a confirmation dialog so the user stays in control. + const iframePromptTypes = ['input:prompt', 'input:prompt:submit', 'action:submit']; + + if (!isSameOrigin && !iframePromptTypes.includes(type)) { return; } - if (event.data.type === 'action:submit') { + if (type === 'action:submit') { console.debug(event.data.text); if (prompt !== '') { @@ -582,8 +591,7 @@ } } - // Replace with your iframe's origin - if (event.data.type === 'input:prompt') { + if (type === 'input:prompt') { console.debug(event.data.text); const inputElement = document.getElementById('chat-input'); @@ -594,12 +602,26 @@ } } - if (event.data.type === 'input:prompt:submit') { + if (type === 'input:prompt:submit') { console.debug(event.data.text); if (event.data.text !== '') { - await tick(); - submitPrompt(event.data.text); + if (isSameOrigin) { + await tick(); + submitPrompt(event.data.text); + } else { + // Cross-origin: ask user to confirm before submitting + eventConfirmationInput = false; + eventConfirmationTitle = $i18n.t('Confirm Prompt from Embed'); + eventConfirmationMessage = event.data.text; + eventCallback = async (confirmed: boolean) => { + if (confirmed) { + await tick(); + submitPrompt(event.data.text); + } + }; + showEventConfirmation = true; + } } } };