|
|
@@ -59,6 +59,9 @@ public class XssSecurityConfig implements InitializingBean { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void afterPropertiesSet() throws Exception { |
|
|
|
if (regex == null || regex.size() == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
StringBuffer tempStr = new StringBuffer("^"); |
|
|
|
regex.forEach(k -> { |
|
|
|
tempStr.append(k); |
|
|
@@ -88,6 +91,7 @@ public class XssSecurityConfig implements InitializingBean { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String securityReplace(String text) { |
|
|
|
if (!initSuccess()) return text; |
|
|
|
if (StringUtils.isEmpty(text)) { |
|
|
|
return text; |
|
|
|
} else { |
|
|
@@ -102,11 +106,16 @@ public class XssSecurityConfig implements InitializingBean { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public boolean matches(String text) { |
|
|
|
if (!initSuccess()) return false; |
|
|
|
if (StringUtils.isEmpty(text)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return XSS_PATTERN.matcher(text).matches(); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean initSuccess() { |
|
|
|
return regex != null && regex.size() > 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|