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