Skip to content

Commit 0ad448b

Browse files
authored
enh: allow iframe postMessage prompts without same-origin (with HITL confirmation) (open-webui#22908)
* Update Chat.svelte * Update Chat.svelte
1 parent 93407ba commit 0ad448b

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,20 @@
569569
origin: string;
570570
data: { type: string; text: string };
571571
}) => {
572-
if (event.origin !== window.origin) {
572+
const isSameOrigin = event.origin === window.origin;
573+
const type = event.data?.type;
574+
575+
// Prompt-related message types only submit text to the chat input —
576+
// functionally equivalent to the user typing. When same-origin is
577+
// enabled they go through immediately. When it is disabled (opaque
578+
// origin) we show a confirmation dialog so the user stays in control.
579+
const iframePromptTypes = ['input:prompt', 'input:prompt:submit', 'action:submit'];
580+
581+
if (!isSameOrigin && !iframePromptTypes.includes(type)) {
573582
return;
574583
}
575584
576-
if (event.data.type === 'action:submit') {
585+
if (type === 'action:submit') {
577586
console.debug(event.data.text);
578587
579588
if (prompt !== '') {
@@ -582,8 +591,7 @@
582591
}
583592
}
584593
585-
// Replace with your iframe's origin
586-
if (event.data.type === 'input:prompt') {
594+
if (type === 'input:prompt') {
587595
console.debug(event.data.text);
588596
589597
const inputElement = document.getElementById('chat-input');
@@ -594,12 +602,26 @@
594602
}
595603
}
596604
597-
if (event.data.type === 'input:prompt:submit') {
605+
if (type === 'input:prompt:submit') {
598606
console.debug(event.data.text);
599607
600608
if (event.data.text !== '') {
601-
await tick();
602-
submitPrompt(event.data.text);
609+
if (isSameOrigin) {
610+
await tick();
611+
submitPrompt(event.data.text);
612+
} else {
613+
// Cross-origin: ask user to confirm before submitting
614+
eventConfirmationInput = false;
615+
eventConfirmationTitle = $i18n.t('Confirm Prompt from Embed');
616+
eventConfirmationMessage = event.data.text;
617+
eventCallback = async (confirmed: boolean) => {
618+
if (confirmed) {
619+
await tick();
620+
submitPrompt(event.data.text);
621+
}
622+
};
623+
showEventConfirmation = true;
624+
}
603625
}
604626
}
605627
};

0 commit comments

Comments
 (0)