diff --git a/src/components/main/GameModal.tsx b/src/components/main/GameModal.tsx index b8b7fa551..a4484e3ea 100644 --- a/src/components/main/GameModal.tsx +++ b/src/components/main/GameModal.tsx @@ -1,12 +1,13 @@ import type { FC } from '../../lib/teact/teact'; import type React from '../../lib/teact/teact'; -import { memo, useCallback, useEffect } from '../../lib/teact/teact'; +import { memo, useCallback, useEffect, useRef } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { TabState } from '../../global/types'; import { getCanPostInChat } from '../../global/helpers'; import { selectChat, selectChatFullInfo } from '../../global/selectors'; +import { isMessageFromIframe } from '../../util/browser/iframe'; import useInterval from '../../hooks/schedulers/useInterval'; import useOldLang from '../../hooks/useOldLang'; @@ -34,6 +35,7 @@ const GameModal: FC = ({ openedGame, gameTitle, canPost } const lang = useOldLang(); const { url, chatId, messageId } = openedGame || {}; const isOpen = Boolean(url); + const frameRef = useRef(); const sendMessageAction = useSendMessageAction(chatId); useInterval(() => { @@ -41,7 +43,10 @@ const GameModal: FC = ({ openedGame, gameTitle, canPost } }, isOpen && canPost ? PLAY_GAME_ACTION_INTERVAL : undefined); const handleMessage = useCallback((event: MessageEvent) => { - if (!chatId || !messageId) return; + if (!chatId || !messageId || !isMessageFromIframe(event, frameRef.current)) { + return; + } + try { const data = JSON.parse(event.data) as GameEvents; if (data.eventType === 'share_score') { @@ -77,6 +82,7 @@ const GameModal: FC = ({ openedGame, gameTitle, canPost } > {isOpen && (