Skip to content

Commit

Permalink
sanitise message content using dompurify to try and stripping it from…
Browse files Browse the repository at this point in the history
… unsafe html such as script tags
  • Loading branch information
nattvara committed Apr 17, 2024
1 parent 206d849 commit 891ab55
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gui/components/chat/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { makeWebsocketUrl } from "@/api/http";
import { TERMINATION_STRING } from "@/api/websocket";

import styles from "./styles.module.css";

Check failure on line 13 in gui/components/chat/Message/Message.tsx

View workflow job for this annotation

GitHub Actions / Lint Typescript files

Delete `";⏎import·DOMPurify·from·"dompurify`

Check failure on line 13 in gui/components/chat/Message/Message.tsx

View workflow job for this annotation

GitHub Actions / Lint Typescript files

Delete `";⏎import·DOMPurify·from·"dompurify`
import DOMPurify from "dompurify";

// 10 minutes
const REFETCH_TIMEOUT = 1000 * 60 * 10;
Expand Down Expand Up @@ -143,6 +144,8 @@ export default function Message(props: MessageProps) {
}
}, [numberOfWords]);

const sanitisedHtml = DOMPurify.sanitize(displayedContent);

return (
<>
{message.feedback_id === null && (
Expand Down Expand Up @@ -175,7 +178,7 @@ export default function Message(props: MessageProps) {
)}
{message.state === MESSAGE_READY && (
<>
<span className={styles.content} dangerouslySetInnerHTML={{ __html: displayedContent }}></span>
<span className={styles.content} dangerouslySetInnerHTML={{ __html: sanitisedHtml }}></span>
{showLoading && (
<span>
<Loader className={styles.loader} ref={loadingRef} color="black" size={12} />
Expand Down

0 comments on commit 891ab55

Please sign in to comment.