fix(frontend): replace v-html with text interpolation in deepThink
Replace v-html + DOMPurify sanitization with plain Vue text
interpolation ({{ }}) and CSS white-space: pre-wrap for the
thinking content display.
The thinking content is raw model output that should never be
interpreted as HTML. Using v-html here created an unnecessary XSS
attack surface — even with DOMPurify, the \n→<br/> replacement
happened before sanitization, and future changes to sanitizer config
could introduce vulnerabilities.
Plain text rendering with pre-wrap:
- Eliminates XSS risk entirely (no HTML parsing)
- Preserves line breaks natively via CSS
- Removes the sanitizeHTML import and safeProcessThinkContent function
- Simpler code with identical visual output
This commit is contained in:
@@ -19,13 +19,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="think-content" v-show="!isFold || deepSession.thinking">
|
||||
<div ref="contentInnerRef" class="content-inner" v-html="safeProcessThinkContent(deepSession.thinkContent)"></div>
|
||||
<div ref="contentInnerRef" class="content-inner">{{ deepSession.thinkContent }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { watch, ref, defineProps, onMounted, nextTick } from 'vue';
|
||||
import { sanitizeHTML } from '@/utils/security';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const isFold = ref(false)
|
||||
@@ -79,19 +78,6 @@ const toggleFold = () => {
|
||||
isFold.value = !isFold.value;
|
||||
}
|
||||
}
|
||||
|
||||
// 安全地处理思考内容,防止XSS攻击
|
||||
const safeProcessThinkContent = (content) => {
|
||||
if (!content || typeof content !== 'string') return '';
|
||||
|
||||
// 先处理换行符
|
||||
const contentWithBreaks = content.replace(/\n/g, '<br/>');
|
||||
|
||||
// 使用DOMPurify进行安全清理,允许基本的文本格式化标签
|
||||
const cleanContent = sanitizeHTML(contentWithBreaks);
|
||||
|
||||
return cleanContent;
|
||||
};
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.deep-think {
|
||||
@@ -204,6 +190,7 @@ const safeProcessThinkContent = (content) => {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
|
||||
Reference in New Issue
Block a user