diff --git a/client/src/components/Messages/Content/Markdown.tsx b/client/src/components/Messages/Content/Markdown.tsx index 89fecd36cc..367e52f1a9 100644 --- a/client/src/components/Messages/Content/Markdown.tsx +++ b/client/src/components/Messages/Content/Markdown.tsx @@ -10,7 +10,7 @@ import supersub from 'remark-supersub'; import remarkGfm from 'remark-gfm'; import rehypeRaw from 'rehype-raw'; import CodeBlock from './CodeBlock'; -import { langSubset } from '~/utils'; +import { langSubset, validateIframe } from '~/utils'; import store from '~/store'; type TCodeProps = { @@ -47,7 +47,7 @@ const Markdown = React.memo(({ content, message, showCursor }: TContentProps) => const isInitializing = content === ''; const isLatestMessage = message?.messageId === latestMessage?.messageId; const currentContent = content?.replace('z-index: 1;', '') ?? ''; - const isIFrame = currentContent.includes(' { let timer1: NodeJS.Timeout, timer2: NodeJS.Timeout; @@ -88,7 +88,7 @@ const Markdown = React.memo(({ content, message, showCursor }: TContentProps) => [rehypeRaw], ]; - if ((!isInitializing || !isLatestMessage) && !isIFrame) { + if ((!isInitializing || !isLatestMessage) && !isValidIFrame) { rehypePlugins.pop(); } diff --git a/client/src/utils/index.ts b/client/src/utils/index.ts index 804525765e..dff114016a 100644 --- a/client/src/utils/index.ts +++ b/client/src/utils/index.ts @@ -5,6 +5,7 @@ export * from './languages'; export { default as getError } from './getError'; export { default as buildTree } from './buildTree'; export { default as cleanupPreset } from './cleanupPreset'; +export { default as validateIframe } from './validateIframe'; export { default as getLocalStorageItems } from './getLocalStorageItems'; export { default as getDefaultConversation } from './getDefaultConversation'; diff --git a/client/src/utils/validateIframe.ts b/client/src/utils/validateIframe.ts new file mode 100644 index 0000000000..302472acfb --- /dev/null +++ b/client/src/utils/validateIframe.ts @@ -0,0 +1,42 @@ +export default function validateIframe(content: string): string | boolean | null { + const hasValidIframe = + content.includes('