diff --git a/frontend/src/components/document-preview.vue b/frontend/src/components/document-preview.vue index 4f83351f..310c0427 100644 --- a/frontend/src/components/document-preview.vue +++ b/frontend/src/components/document-preview.vue @@ -6,6 +6,7 @@ import { MessagePlugin } from 'tdesign-vue-next'; import hljs from 'highlight.js'; import 'highlight.js/styles/github.css'; import { useI18n } from 'vue-i18n'; +import { sanitizeHTML, safeMarkdownToHTML } from '@/utils/security'; const VueOfficePptx = defineAsyncComponent(() => import('@vue-office/pptx')); @@ -174,7 +175,7 @@ async function renderExcel(blob: Blob, fileType?: string) { html += sheetHtml; html += ``; }); - excelHtml.value = html; + excelHtml.value = sanitizeHTML(html); } async function renderText(blob: Blob, fileType: string) { @@ -223,7 +224,9 @@ async function renderMarkdown(blob: Blob) { return `
${highlighted}
`; }; marked.use({ renderer }); - markdownHtml.value = marked.parse(text); + const safeText = safeMarkdownToHTML(text); + const rawHtml = marked.parse(safeText); + markdownHtml.value = sanitizeHTML(rawHtml); } function onImageLoad(e: Event) { diff --git a/frontend/src/views/chat/components/botmsg.vue b/frontend/src/views/chat/components/botmsg.vue index 059eea8a..993ecf40 100644 --- a/frontend/src/views/chat/components/botmsg.vue +++ b/frontend/src/views/chat/components/botmsg.vue @@ -189,10 +189,6 @@ const renderToken = (token) => { } }; -const myMarkdown = (res) => { - return marked.parse(res, { renderer }) -} - // 获取实际内容 const getActualContent = () => { return (props.content || props.session?.content || '').trim();