|
|
@@ -5,7 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.constant.SecurityFilterProperties;
|
|
|
-import org.jeecg.common.exception.BadHttpRequestException;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.util.SecurityUtils;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
@@ -55,7 +55,6 @@ public class XssAndSqlInjectionFilter implements Filter {
|
|
|
* 默认需要检查的请求头
|
|
|
*/
|
|
|
private static final Set<String> DEFAULT_CHECK_HEADERS = new HashSet<>(Arrays.asList(
|
|
|
- "User-Agent",
|
|
|
"Referer",
|
|
|
"X-Forwarded-For"
|
|
|
));
|
|
|
@@ -80,9 +79,9 @@ public class XssAndSqlInjectionFilter implements Filter {
|
|
|
// 包装请求,进行安全检查
|
|
|
SecurityRequestWrapper wrappedRequest = new SecurityRequestWrapper(httpRequest);
|
|
|
chain.doFilter(wrappedRequest, response);
|
|
|
- } catch (BadHttpRequestException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("检测到恶意请求,URL: {}, 错误信息: {}", httpRequest.getRequestURI(), e.getMessage());
|
|
|
- throw e;
|
|
|
+ throw new JeecgBootException("用户输入包含非法内容,请输入合法内容!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -229,12 +228,13 @@ public class XssAndSqlInjectionFilter implements Filter {
|
|
|
private void checkContent(String content, String location) {
|
|
|
// XSS 检测
|
|
|
if (properties.getXssEnabled() && SecurityUtils.containsXss(content)) {
|
|
|
- throw new BadHttpRequestException("检测到 XSS 攻击尝试,位置: " + location);
|
|
|
+// throw new JeecgBootException("检测到 XSS 攻击尝试,位置: " + location);
|
|
|
+ throw new JeecgBootException("用户输入包含非法内容,请输入合法内容!");
|
|
|
}
|
|
|
|
|
|
// SQL 注入检测
|
|
|
if (properties.getSqlInjectionEnabled() && SecurityUtils.containsSqlInjection(content)) {
|
|
|
- throw new BadHttpRequestException("检测到 SQL 注入尝试,位置: " + location);
|
|
|
+ throw new JeecgBootException("用户输入包含非法内容,请输入合法内容!");
|
|
|
}
|
|
|
}
|
|
|
|