diff --git a/frontend/src/utils/security.ts b/frontend/src/utils/security.ts index 76c5cd11..b1eab2f0 100644 --- a/frontend/src/utils/security.ts +++ b/frontend/src/utils/security.ts @@ -12,7 +12,7 @@ const DOMPurifyConfig = { 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'a', 'img', 'table', 'thead', 'tbody', 'tr', 'th', 'td', - 'div', 'span', 'figure', 'figcaption' + 'div', 'span', 'figure', 'figcaption', 'think' ], // 允许的属性 ALLOWED_ATTR: [ diff --git a/frontend/src/views/chat/components/deepThink.vue b/frontend/src/views/chat/components/deepThink.vue index 49e0f2b8..36bd149c 100644 --- a/frontend/src/views/chat/components/deepThink.vue +++ b/frontend/src/views/chat/components/deepThink.vue @@ -19,7 +19,7 @@
- +
@@ -53,6 +53,19 @@ const showHide = () => { const handlePanelChange = (val) => { isFold.value = !val.length ? true : false; } + +// 安全地处理思考内容,防止XSS攻击 +const safeProcessThinkContent = (content) => { + if (!content || typeof content !== 'string') return ''; + + // 先处理换行符 + const contentWithBreaks = content.replace(/\n/g, '
'); + + // 使用DOMPurify进行安全清理,允许基本的文本格式化标签 + const cleanContent = sanitizeHTML(contentWithBreaks); + + return cleanContent; +};