Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 6a0038a

Browse files
authored
chore(ui): html/markdown security (#1006)
1 parent 6d17187 commit 6a0038a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/leapfrogai_ui/src/lib/components/Message.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
4242
// used for code formatting and handling
4343
const md = markdownit({
44+
html: true,
4445
highlight: function (str: string, language: string) {
4546
let code: string;
4647
if (language && hljs.getLanguage(language)) {
@@ -178,7 +179,13 @@
178179
<MessagePendingSkeleton size="sm" class="mt-4" darkColor="bg-gray-500" />
179180
{:else}
180181
<!--eslint-disable-next-line svelte/no-at-html-tags -- We use DomPurity to sanitize the code snippet-->
181-
{@html md.render(DOMPurify.sanitize(messageText))}
182+
{@html DOMPurify.sanitize(md.render(messageText), {
183+
CUSTOM_ELEMENT_HANDLING: {
184+
tagNameCheck: /^code-block$/,
185+
attributeNameCheck: /^(code|language)$/,
186+
allowCustomizedBuiltInElements: false
187+
}
188+
})}
182189
<div class="flex flex-col items-start">
183190
{#each getCitations(message, $page.data.files) as { component: Component, props }}
184191
<svelte:component this={Component} {...props} />

src/leapfrogai_ui/src/lib/web-components/CodeBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class CodeBlock extends LitElement {
7979

8080
removeHtml = () => {
8181
const tmp = document.createElement('DIV');
82-
tmp.innerHTML = this.code;
82+
tmp.innerHTML = DOMPurify.sanitize(this.code);
8383
return tmp.textContent || tmp.innerText || '';
8484
};
8585

0 commit comments

Comments
 (0)