From 56fb212cc685f182643ec352381c6441ea707716 Mon Sep 17 00:00:00 2001 From: scott Date: Sat, 31 Oct 2026 23:27:03 -0400 Subject: [PATCH] =?UTF-8?q?fix(security):=20Online=20=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=AD=98=E5=82=A8=E5=9E=8B=20XSS=EF=BC=88GHS?= =?UTF-8?q?A-867f-2922-wj26=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - textarea 字段先转义 HTML 再换行,不再把原始值直接交给 v-html - 富文本字段渲染前经 sanitizeRichText 净化 - htmlSanitizer 新增 escapeHtml Co-Authored-By: Claude Opus 5.5 --- jeecgboot-vue3/src/utils/htmlSanitizer.ts | 14 ++++++++++++++ .../super/online/cgform/extend/form/DetailForm.vue | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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, }; }, });