Skip to content

Commit 5e74458

Browse files
committedJun 10, 2024·
Merge branch 'escape_html_tags' into 'master'
Bot UI: ignore unsafe HTML tags in Markdown renderer See merge request postgres-ai/database-lab!876
2 parents 978edf9 + abf835c commit 5e74458

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
 

‎ui/packages/platform/src/pages/Bot/DebugDialog/DebugDialog.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DialogContent, IconButton, makeStyles, Typography } from "@material-ui/
55
import ReactMarkdown from "react-markdown";
66
import Format from "../../../utils/format";
77
import { icons } from "@postgres.ai/shared/styles/icons";
8+
import { disallowedHtmlTagsForMarkdown } from "../utils";
89

910
type DebugDialogProps = {
1011
isOpen: boolean;
@@ -80,6 +81,8 @@ export const DebugDialog = (props: DebugDialogProps) => {
8081
components={{
8182
p: 'div',
8283
}}
84+
disallowedElements={disallowedHtmlTagsForMarkdown}
85+
unwrapDisallowed
8386
>
8487
{debugMessage.message}
8588
</ReactMarkdown>

‎ui/packages/platform/src/pages/Bot/Messages/Message/Message.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { colors } from "@postgres.ai/shared/styles/colors";
88
import { icons } from "@postgres.ai/shared/styles/icons";
99
import { DebugDialog } from "../../DebugDialog/DebugDialog";
1010
import { CodeBlock } from "./CodeBlock";
11-
import { permalinkLinkBuilder } from "../../utils";
11+
import { disallowedHtmlTagsForMarkdown, permalinkLinkBuilder } from "../../utils";
1212

1313
type BaseMessageProps = {
1414
id: string | null;
@@ -321,6 +321,8 @@ export const Message = React.memo((props: MessageProps) => {
321321
remarkPlugins={[remarkGfm]}
322322
linkTarget='_blank'
323323
components={renderers}
324+
disallowedElements={disallowedHtmlTagsForMarkdown}
325+
unwrapDisallowed
324326
/>
325327
}
326328
</div>

‎ui/packages/platform/src/pages/Bot/utils.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,22 @@ export const permalinkLinkBuilder = (id: string): string => {
1111
const apiUrl = process.env.REACT_APP_API_URL_PREFIX || API_URL_PREFIX;
1212
const isV2API = /https?:\/\/.*v2\.postgres\.ai\b/.test(apiUrl);
1313
return `https://${isV2API ? 'v2.' : ''}postgres.ai/chats/${id}`;
14-
};
14+
};
15+
16+
export const disallowedHtmlTagsForMarkdown= [
17+
'script',
18+
'style',
19+
'iframe',
20+
'form',
21+
'input',
22+
'link',
23+
'meta',
24+
'embed',
25+
'object',
26+
'applet',
27+
'base',
28+
'frame',
29+
'frameset',
30+
'audio',
31+
'video',
32+
]

0 commit comments

Comments
 (0)
Please sign in to comment.