Skip to content

Commit 677faa0

Browse files
committed
refactor: disable iframe in message markdown render
1 parent f74647f commit 677faa0

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

client/web/plugins/com.msgbyte.mdpanel/src/group/MarkdownPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const MarkdownPanel: React.FC = React.memo(() => {
5454
render={(dataMap: Record<string, string>) => {
5555
return (
5656
<MainContent>
57-
<Markdown raw={dataMap['markdown'] ?? ''} />
57+
<Markdown raw={dataMap['markdown'] ?? ''} allowIframe={true} />
5858
</MainContent>
5959
);
6060
}}

client/web/src/components/Markdown/render.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ const ReactMarkdown = Loadable(() => import('react-markdown'));
1313

1414
export const Markdown: React.FC<{
1515
raw: string;
16+
allowIframe?: boolean;
1617
baseUrl?: string;
17-
}> = React.memo(({ raw, baseUrl }) => {
18+
}> = React.memo(({ raw, baseUrl, allowIframe }) => {
1819
const { t } = useTranslation();
1920
const transformUrl = useCallback(
2021
(url: string) => {
@@ -46,21 +47,27 @@ export const Markdown: React.FC<{
4647
),
4748
svg: () => <div>not support svg</div>,
4849
iframe: (props) => {
50+
if (!allowIframe) {
51+
return <div>{t('不支持iframe')}</div>;
52+
}
53+
4954
let src = props.src;
5055

5156
if (!src) {
5257
return <div />;
5358
}
5459

5560
if (!src.startsWith('http')) {
56-
return <div>only support http source</div>;
61+
return <div>{t('只支持http路径')}</div>;
5762
}
5863

5964
if (src && src.includes('?')) {
6065
src += '&autoplay=0'; // make sure media autoplay is false
6166
}
6267
return <iframe {...props} src={src} />;
6368
},
69+
embed: () => <div>{t('不支持embed')}</div>,
70+
html: () => <div>{t('不支持自定义HTML')}</div>,
6471
style: () => <div>{t('不支持自定义样式')}</div>,
6572
meta: () => <div>{t('不支持自定义Meta')}</div>,
6673
}),

client/web/src/plugin/PluginStore/DocumentView/DocumentMarkdownRender.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const DocumentMarkdownRender: React.FC<{ url: string }> = React.memo(
2424
return <Problem text={String(error)} />;
2525
}
2626

27-
return <Markdown raw={String(value)} baseUrl={url} />;
27+
return <Markdown raw={String(value)} baseUrl={url} allowIframe={true} />;
2828
}
2929
);
3030
DocumentMarkdownRender.displayName = 'DocumentMarkdownRender';

0 commit comments

Comments
 (0)