作者 RuoYi

HTML过滤器改为将html转义

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