Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: remove markdown sanitisation to keep custom html tags for users (#2656)

marliessophie6f62cf5f47dd
diff --git a/web/src/components/ui/MarkdownViewer.tsx b/web/src/components/ui/MarkdownViewer.tsx
index 894b1c16eb..7fee4c0b13 100644
--- a/web/src/components/ui/MarkdownViewer.tsx
+++ b/web/src/components/ui/MarkdownViewer.tsx
@@ -11,7 +11,6 @@ import {
} from "react";
import ReactMarkdown, { type Options } from "react-markdown";
import Link from "next/link";
-import DOMPurify from "dompurify";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import { CodeBlock } from "@/src/components/ui/Codeblock";
@@ -21,6 +20,8 @@ import { Check, Copy } from "lucide-react";
import { BsMarkdown } from "react-icons/bs";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+// ReactMarkdown does not render raw HTML by default for security reasons, to prevent XSS (Cross-Site Scripting) attacks.
+// html is rendered as plain text by default.
const MemoizedReactMarkdown: FC<Options> = memo(
ReactMarkdown,
(prevProps, nextProps) =>
@@ -67,8 +68,6 @@ export function MarkdownView({
const { resolvedTheme: theme } = useTheme();
const capture = usePostHogClientCapture();
- const sanitizedMarkdown = DOMPurify.sanitize(markdown);
-
const handleCopy = () => {
setIsCopied(true);
void navigator.clipboard.writeText(markdown);
@@ -121,11 +120,16 @@ export function MarkdownView({
</div>
) : undefined}
<MemoizedReactMarkdown
- className={cn("space-y-4 break-words p-3 font-mono text-xs", className)}
+ className={cn(
+ "space-y-4 overflow-x-auto break-words p-3 font-mono text-xs",
+ className,
+ )}
remarkPlugins={[remarkGfm, remarkMath]}
components={{
p({ children }) {
- return <p className="mb-2 last:mb-0">{children}</p>;
+ return (
+ <p className="mb-2 whitespace-pre-wrap last:mb-0">{children}</p>
+ );
},
a({ children, href }) {
if (href)
@@ -234,7 +238,7 @@ export function MarkdownView({
},
}}
>
- {sanitizedMarkdown}
+ {markdown}
</MemoizedReactMarkdown>
</div>
);