|
569 | 569 | origin: string; |
570 | 570 | data: { type: string; text: string }; |
571 | 571 | }) => { |
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)) { |
573 | 582 | return; |
574 | 583 | } |
575 | 584 |
|
576 | | - if (event.data.type === 'action:submit') { |
| 585 | + if (type === 'action:submit') { |
577 | 586 | console.debug(event.data.text); |
578 | 587 |
|
579 | 588 | if (prompt !== '') { |
|
582 | 591 | } |
583 | 592 | } |
584 | 593 |
|
585 | | - // Replace with your iframe's origin |
586 | | - if (event.data.type === 'input:prompt') { |
| 594 | + if (type === 'input:prompt') { |
587 | 595 | console.debug(event.data.text); |
588 | 596 |
|
589 | 597 | const inputElement = document.getElementById('chat-input'); |
|
594 | 602 | } |
595 | 603 | } |
596 | 604 |
|
597 | | - if (event.data.type === 'input:prompt:submit') { |
| 605 | + if (type === 'input:prompt:submit') { |
598 | 606 | console.debug(event.data.text); |
599 | 607 |
|
600 | 608 | 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 | + } |
603 | 625 | } |
604 | 626 | } |
605 | 627 | }; |
|
0 commit comments