diff --git a/jeecgboot-vue3/src/utils/htmlSanitizer.ts b/jeecgboot-vue3/src/utils/htmlSanitizer.ts index f120bc7d3..2b346b14d 100644 --- a/jeecgboot-vue3/src/utils/htmlSanitizer.ts +++ b/jeecgboot-vue3/src/utils/htmlSanitizer.ts @@ -117,6 +117,20 @@ export function sanitizeRichText(value: unknown): string { return xss(normalizeHtml(value), richTextOptions); } +/** + * 转义 HTML 特殊字符,用于把纯文本安全地拼进 v-html + * @author scott + * @since 2026-10-31 【GHSA-867f-2922-wj26】Online 表单详情多行文本存储型 XSS + */ +export function escapeHtml(value: unknown): string { + return normalizeHtml(value) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + /** 净化评论预览和评论列表,只允许换行及系统生成的 emoji 标签。 */ export function sanitizeCommentHtml(value: unknown): string { //console.log("xss filter value:", value); diff --git a/jeecgboot-vue3/src/views/super/online/cgform/extend/form/DetailForm.vue b/jeecgboot-vue3/src/views/super/online/cgform/extend/form/DetailForm.vue index 9db4e1bea..2776a0f2a 100644 --- a/jeecgboot-vue3/src/views/super/online/cgform/extend/form/DetailForm.vue +++ b/jeecgboot-vue3/src/views/super/online/cgform/extend/form/DetailForm.vue @@ -8,7 +8,9 @@
-
+ +
+
@@ -74,6 +76,7 @@ import LinkTableCard from '../linkTable/LinkTableCard.vue' import { MarkdownViewer } from '/@/components/Markdown'; import { getWeekMonthQuarterYear } from '/@/utils'; + import { sanitizeRichText, escapeHtml } from '/@/utils/htmlSanitizer'; export default defineComponent({ name: 'DetailForm', @@ -107,6 +110,12 @@ // update-end--author:liaozhiyang---date:20230925---for:【QQYUN-6647】页面配置中高级配置中设置的label长度,在列表与详情界面无效 // update-begin--author:liusq---date:20240527---for:【TV360X-464】多行文本换行显示 const textareaLineBreak = (content) => { + // update-begin--author:scott---date:20261031---for:【GHSA-867f-2922-wj26】多行文本只换行不转义,v-html 渲染导致存储型XSS,先转义再换行 + if (content == null || content === '') { + return content; + } + content = escapeHtml(content); + // update-end--author:scott---date:20261031---for:【GHSA-867f-2922-wj26】多行文本只换行不转义,v-html 渲染导致存储型XSS,先转义再换行 if (content && content.includes('\n')) { content = content.replace(/\n/g, '
'); } @@ -147,7 +156,8 @@ getLabelWidthClass, filterLable, filter, - textareaLineBreak + textareaLineBreak, + sanitizeRichText, }; }, });