From 22225a5119e3b1c10d26bb68975fb19e87037b8c Mon Sep 17 00:00:00 2001 From: RuoYi Date: Tue, 28 Jul 2020 17:28:09 +0800 Subject: [PATCH] =?UTF-8?q?HTML=E8=BF=87=E6=BB=A4=E5=99=A8=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=B0=86html=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/common/utils/html/EscapeUtil.java | 5 ++++- .../main/java/com/ruoyi/common/utils/html/HTMLFilter.java | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java index 8989ca1e..121681b4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java @@ -144,7 +144,10 @@ public class EscapeUtil public static void main(String[] args) { - String html = "alert('11111');"; + String html = ""; + // String html = "ipt>alert(\"XSS\")ipt>"; + // String html = "<123"; + // String html = "123>"; System.out.println(EscapeUtil.clean(html)); System.out.println(EscapeUtil.escape(html)); System.out.println(EscapeUtil.unescape(html)); diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/HTMLFilter.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/HTMLFilter.java index 41739569..3de26bb4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/HTMLFilter.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/html/HTMLFilter.java @@ -131,7 +131,7 @@ public final class HTMLFilter vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" }; stripComment = true; encodeQuotes = true; - alwaysMakeTags = true; + alwaysMakeTags = false; } /** @@ -208,7 +208,7 @@ public final class HTMLFilter s = processRemoveBlanks(s); - s = validateEntities(s); + // s = validateEntities(s); return s; } @@ -245,6 +245,7 @@ public final class HTMLFilter // try and form html // s = regexReplace(P_END_ARROW, "", s); + // 不追加结束标签 s = regexReplace(P_BODY_TO_END, "<$1>", s); s = regexReplace(P_XML_CONTENT, "$1<$2", s);