- 一、漏洞描述
- 二、解决建议
- 三、解决方法
- Springboot 配置文件增加配置
- 编写配置类
- 编写过滤器
提示:以下是本篇文章正文内容,下面案例可供参考 一、漏洞描述
可能会升级用户特权并通过 Web 应用程序获取管理许可权可能会收集有关 Web 应用程序的敏感信息,如用户名、密码、机器名和/或敏感文件位置。
测试结果似乎指示存在脆弱性,因为“测试响应”与“原始响应”完全相同,这表明动词篡改能够绕过站点认证。
增加拦截器,判断请求方式是否合法,合法则放行。
三、解决方法 Springboot 配置文件增加配置# 信息安全
security:
#http请求方式配置
http:
#是否开启(开启:true 关闭:false)
enable: false
#允许的请求方式
allow:
- POST
- GET
编写配置类
@Component
@Configuration
@ConfigurationProperties(prefix = "security")
public class SecurityConfig implements InitializingBean, DisposableBean {
private static Logger logger = LoggerFactory.getLogger(AspctConfig.class);
private HttpConfig http;
private XssConfig xss;
public HttpConfig getHttp() {
return http;
}
public void setHttp(HttpConfig http) {
this.http = http;
}
public XssConfig getXss() {
return xss;
}
public void setXss(XssConfig xss) {
this.xss = xss;
}
@Override
public void destroy() throws Exception {
}
@Override
public void afterPropertiesSet() throws Exception {
}
@Bean
@ConditionalOnProperty(prefix = "security", name = "http.enable", havingValue = "true")
public FilterRegistrationBean httpFilterRegistration() {
logger.info("hhtp过滤器初始化");
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setName("httpFilter");
registration.setOrder(3);
registration.addUrlPatterns("
public class HttpConfig {
private boolean enable;
private List allow;
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public List getAllow() {
return allow;
}
public void setAllow(List allow) {
this.allow = allow;
}
}
编写过滤器
public class HttpFilter implements Filter {
private static Logger LOGGER = LoggerFactory.getLogger(CsrfFilter.class);
FilterConfig filterConfig = null;
private SecurityConfig security;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
security = SpringUtils.getBean(SecurityConfig.class);
this.filterConfig = filterConfig;
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
String method = request.getMethod();
if (isExcludeMethod(method)) {
filterChain.doFilter(servletRequest, servletResponse);
return;
} else {
servletResponse.setContentType("application/json; charset=UTF-8");
servletResponse.getWriter().write(JacksonUtil.writeValueAsString(new ReturnT<>(ReturnT.FAIL_CODE, "不支持的请求方式!")));
LOGGER.error("不支持的请求方式", method);
}
}
@Override
public void destroy() {
Filter.super.destroy();
}
private boolean isExcludeMethod(String method) {
if (security.getHttp().getAllow() == null || security.getHttp().getAllow().isEmpty()) {
return false;
}
return security.getHttp().getAllow().stream().map(pattern -> Pattern.compile("^" + pattern)).map(p -> p.matcher(method))
.anyMatch(Matcher::find);
}
}



