2026-08-16 01:17:18 +02:00
|
|
|
// TODO: P3-F21 — Remove redundant regex before DOMPurify
|
2026-07-22 01:22:15 +02:00
|
|
|
import React from 'react';
|
2026-07-25 21:03:46 +02:00
|
|
|
import DOMPurify from 'dompurify';
|
2026-07-22 01:22:15 +02:00
|
|
|
import type { MessageBlock } from '@/store/commStore';
|
|
|
|
|
|
|
|
|
|
interface HtmlBlockProps {
|
|
|
|
|
block: MessageBlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const HtmlBlock: React.FC<HtmlBlockProps> = ({ block }) => {
|
|
|
|
|
const rawHtml: string = block.block_data.html || '';
|
|
|
|
|
|
|
|
|
|
if (!rawHtml) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-04 19:25:44 +02:00
|
|
|
// Replace javascript: URLs in href attributes before sanitizing
|
|
|
|
|
const safeHtml = rawHtml.replace(
|
|
|
|
|
/href\s*=\s*(["'])\s*javascript:[^"']*\1/gi,
|
|
|
|
|
'href=$1#$1'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const sanitized = DOMPurify.sanitize(safeHtml);
|
2026-07-22 01:22:15 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="prose prose-sm max-w-none text-inherit"
|
|
|
|
|
dangerouslySetInnerHTML={{ __html: sanitized }}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default HtmlBlock;
|