diff --git a/src/lib/ircUtils.tsx b/src/lib/ircUtils.tsx
index ba606063..a45fabec 100644
--- a/src/lib/ircUtils.tsx
+++ b/src/lib/ircUtils.tsx
@@ -240,6 +240,9 @@ export function renderMarkdown(
return `${text}`;
};
+ // Strip all HTML tags from input before markdown processing
+ const textWithoutHtml = text.replace(/<[^>]*>/g, "");
+
marked.setOptions({
breaks: true,
gfm: true,
@@ -247,17 +250,74 @@ export function renderMarkdown(
});
// Parse markdown to HTML
- const html = marked.parse(text) as string;
-
- // Additional security: remove any remaining script tags or dangerous content that might have slipped through
- const sanitizedHtml = html
+ const html = marked.parse(textWithoutHtml) as string;
+
+ // Additional security: only allow specific markdown-related HTML tags
+ // Define allowed HTML tags for markdown rendering
+ const allowedTags = new Set([
+ "p",
+ "br",
+ "strong",
+ "b",
+ "em",
+ "i",
+ "h1",
+ "h2",
+ "h3",
+ "h4",
+ "h5",
+ "h6",
+ "ul",
+ "ol",
+ "li",
+ "blockquote",
+ "code",
+ "pre",
+ "a",
+ "img",
+ "hr",
+ "table",
+ "thead",
+ "tbody",
+ "tr",
+ "th",
+ "td",
+ "del",
+ "ins",
+ ]);
+
+ // Remove dangerous content first
+ let sanitizedHtml = html
.replace(/