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:
lyingbug
2026-03-20 22:53:42 +00:00
committed by lyingbug
parent 34d711d15f
commit 03fda55261
@@ -19,13 +19,12 @@
</div> </div>
</div> </div>
<div class="think-content" v-show="!isFold || deepSession.thinking"> <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>
</div> </div>
</template> </template>
<script setup> <script setup>
import { watch, ref, defineProps, onMounted, nextTick } from 'vue'; import { watch, ref, defineProps, onMounted, nextTick } from 'vue';
import { sanitizeHTML } from '@/utils/security';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
const isFold = ref(false) const isFold = ref(false)
@@ -79,19 +78,6 @@ const toggleFold = () => {
isFold.value = !isFold.value; 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> </script>
<style lang="less" scoped> <style lang="less" scoped>
.deep-think { .deep-think {
@@ -204,6 +190,7 @@ const safeProcessThinkContent = (content) => {
max-height: 200px; max-height: 200px;
overflow-y: auto; overflow-y: auto;
word-break: break-word; word-break: break-word;
white-space: pre-wrap;
&::-webkit-scrollbar { &::-webkit-scrollbar {
width: 4px; width: 4px;