Commit 22225a5119e3b1c10d26bb68975fb19e87037b8c

Authored by RuoYi
1 parent fe030cc0

HTML过滤器改为将html转义

ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java
... ... @@ -144,7 +144,10 @@ public class EscapeUtil
144 144  
145 145 public static void main(String[] args)
146 146 {
147   - String html = "alert('11111');";
  147 + String html = "<script>alert(1);</script>";
  148 + // String html = "<scr<script>ipt>alert(\"XSS\")</scr<script>ipt>";
  149 + // String html = "<123";
  150 + // String html = "123>";
148 151 System.out.println(EscapeUtil.clean(html));
149 152 System.out.println(EscapeUtil.escape(html));
150 153 System.out.println(EscapeUtil.unescape(html));
... ...
ruoyi-common/src/main/java/com/ruoyi/common/utils/html/HTMLFilter.java
... ... @@ -131,7 +131,7 @@ public final class HTMLFilter
131 131 vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" };
132 132 stripComment = true;
133 133 encodeQuotes = true;
134   - alwaysMakeTags = true;
  134 + alwaysMakeTags = false;
135 135 }
136 136  
137 137 /**
... ... @@ -208,7 +208,7 @@ public final class HTMLFilter
208 208  
209 209 s = processRemoveBlanks(s);
210 210  
211   - s = validateEntities(s);
  211 + // s = validateEntities(s);
212 212  
213 213 return s;
214 214 }
... ... @@ -245,6 +245,7 @@ public final class HTMLFilter
245 245 // try and form html
246 246 //
247 247 s = regexReplace(P_END_ARROW, "", s);
  248 + // 不追加结束标签
248 249 s = regexReplace(P_BODY_TO_END, "<$1>", s);
249 250 s = regexReplace(P_XML_CONTENT, "$1<$2", s);
250 251  
... ...