v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -44,7 +44,6 @@ export interface HtmlContentProps {
|
||||
* @example
|
||||
* // HTML 렌더링 (기본값)
|
||||
* <HtmlContent content="<p>안녕하세요</p>" />
|
||||
* <HtmlContent content="<p>안녕하세요</p>" isHtml={true} />
|
||||
*
|
||||
* // 일반 텍스트 렌더링
|
||||
* <HtmlContent
|
||||
@@ -95,41 +94,57 @@ export const HtmlContent: React.FC<HtmlContentProps> = ({
|
||||
);
|
||||
}
|
||||
|
||||
// isHtml=true: HTML 렌더링 (기존 로직)
|
||||
// 기본 DOMPurify 설정
|
||||
// 기본 DOMPurify 설정 (FORBID 방식: 위험 태그/속성만 차단, 나머지 허용)
|
||||
const defaultConfig: any = {
|
||||
ALLOWED_TAGS: [
|
||||
'p', 'br', 'strong', 'em', 'u', 's', 'strike', 'del', 'ins', 'mark',
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
||||
'ul', 'ol', 'li',
|
||||
'a', 'img',
|
||||
'blockquote', 'code', 'pre',
|
||||
'table', 'thead', 'tbody', 'tr', 'th', 'td',
|
||||
'div', 'span',
|
||||
FORBID_TAGS: [
|
||||
// 스크립트 실행
|
||||
'script', 'noscript',
|
||||
// 외부 콘텐츠 삽입
|
||||
'iframe', 'frame', 'frameset', 'object', 'embed', 'applet', 'portal',
|
||||
// 폼 요소 (피싱 방지)
|
||||
'form', 'input', 'textarea', 'select', 'button',
|
||||
// 메타/스타일 조작
|
||||
'style', 'link', 'meta', 'base',
|
||||
// 구조 태그 주입
|
||||
'body', 'head', 'html', 'title',
|
||||
// SVG/MathML (XSS 벡터)
|
||||
'svg', 'math',
|
||||
// 미디어 이벤트 핸들러 (onerror, onloadstart)
|
||||
'audio', 'video', 'source', 'track', 'canvas',
|
||||
// UI 오버레이/이벤트
|
||||
'details', 'dialog',
|
||||
// HTML 파서 혼란/sanitizer 우회
|
||||
'plaintext', 'xmp', 'listing',
|
||||
// 레거시/비표준
|
||||
'marquee', 'noframes', 'noembed', 'template', 'slot',
|
||||
],
|
||||
ALLOWED_ATTR: [
|
||||
'href', 'target', 'rel', 'title', 'alt', 'src', 'width', 'height',
|
||||
'class', 'style', 'id', 'data-*',
|
||||
FORBID_ATTR: [
|
||||
'onerror', 'onload', 'onclick', 'onmouseover', 'onfocus', 'onblur',
|
||||
'ontoggle', 'oncanplay', 'onloadstart',
|
||||
'formaction', 'xlink:href', 'action',
|
||||
],
|
||||
ALLOW_DATA_ATTR: true,
|
||||
// 외부 링크는 rel="noopener noreferrer" 자동 추가
|
||||
ADD_ATTR: ['target'],
|
||||
// target="_blank"인 링크에 rel="noopener noreferrer" 자동 추가
|
||||
SAFE_FOR_TEMPLATES: true,
|
||||
};
|
||||
|
||||
// sanitize된 HTML을 메모이제이션
|
||||
const sanitizedHtml = useMemo(() => {
|
||||
const config = purifyConfig || defaultConfig;
|
||||
const config = purifyConfig
|
||||
? {
|
||||
...defaultConfig,
|
||||
...purifyConfig,
|
||||
// 보안 기본값은 항상 유지 (사용자 설정으로 덮어쓰기 방지)
|
||||
FORBID_TAGS: [...defaultConfig.FORBID_TAGS, ...(purifyConfig.FORBID_TAGS || [])],
|
||||
FORBID_ATTR: [...defaultConfig.FORBID_ATTR, ...(purifyConfig.FORBID_ATTR || [])],
|
||||
}
|
||||
: defaultConfig;
|
||||
const cleaned = DOMPurify.sanitize(actualContent, config) as unknown as string;
|
||||
|
||||
// target="_blank" 링크에 rel 속성 추가 (보안)
|
||||
return cleaned.replace(
|
||||
/<a\s+([^>]*?)href=["']([^"']+)["']([^>]*?)>/gi,
|
||||
(match: string, before: string, href: string, after: string) => {
|
||||
// 외부 링크인 경우
|
||||
if (href.startsWith('http://') || href.startsWith('https://')) {
|
||||
// rel 속성이 없으면 추가
|
||||
if (!match.includes('rel=')) {
|
||||
return `<a ${before}href="${href}"${after} rel="noopener noreferrer">`;
|
||||
}
|
||||
@@ -137,7 +152,7 @@ export const HtmlContent: React.FC<HtmlContentProps> = ({
|
||||
return match;
|
||||
}
|
||||
);
|
||||
}, [actualContent, purifyConfig, defaultConfig]);
|
||||
}, [actualContent, purifyConfig]);
|
||||
|
||||
// 컨테이너 클래스 조합
|
||||
const containerClasses = `
|
||||
@@ -147,19 +162,20 @@ export const HtmlContent: React.FC<HtmlContentProps> = ({
|
||||
prose-h1:text-2xl prose-h2:text-xl prose-h3:text-lg
|
||||
prose-a:text-blue-600 dark:prose-a:text-blue-400
|
||||
prose-a:no-underline hover:prose-a:underline
|
||||
prose-img:rounded-lg prose-img:shadow-md
|
||||
prose-blockquote:border-l-4 prose-blockquote:border-gray-300 dark:prose-blockquote:border-gray-600
|
||||
prose-blockquote:pl-4 prose-blockquote:italic
|
||||
prose-code:bg-gray-100 dark:prose-code:bg-gray-800
|
||||
prose-code:px-1 prose-code:py-0.5 prose-code:rounded
|
||||
prose-pre:bg-gray-100 dark:prose-pre:bg-gray-800
|
||||
prose-pre:p-4 prose-pre:rounded-lg prose-pre:overflow-x-auto
|
||||
prose-table:border prose-table:border-gray-300 dark:prose-table:border-gray-600
|
||||
prose-th:bg-gray-100 dark:prose-th:bg-gray-800
|
||||
prose-th:border prose-th:border-gray-300 dark:prose-th:border-gray-600
|
||||
prose-th:px-4 prose-th:py-2
|
||||
prose-td:border prose-td:border-gray-300 dark:prose-td:border-gray-600
|
||||
prose-td:px-4 prose-td:py-2
|
||||
[&_table]:w-full [&_table]:border-collapse [&_table]:border [&_table]:border-gray-300
|
||||
dark:[&_table]:border-gray-600
|
||||
[&_th]:border [&_th]:border-gray-300 [&_th]:px-4 [&_th]:py-2 [&_th]:bg-gray-100 [&_th]:text-left
|
||||
dark:[&_th]:border-gray-600 dark:[&_th]:bg-gray-800
|
||||
[&_td]:border [&_td]:border-gray-300 [&_td]:px-4 [&_td]:py-2
|
||||
dark:[&_td]:border-gray-600
|
||||
[&_tr:hover]:bg-gray-50 dark:[&_tr:hover]:bg-gray-700/50
|
||||
after:content-[''] after:block after:clear-both
|
||||
${className}
|
||||
`.trim().replace(/\s+/g, ' ');
|
||||
|
||||
|
||||
Reference in new issue
Block a user