0


springboot解决不安全的HTTP请求方式安全漏洞

简介

在安全漏洞中,有不安全的HTTP请求方式;
原因:
1、Tomcat PUT 的上传漏洞,受影响的版本:Apache Tomcat 7.0.0 to 7.0.79
2、 Nginx 在开启 WebDAV 模式下,如果未配置认证模式,攻击者可以通过自由上传文件方法上传木马攻击服务器。

整改建议:

禁止使用GET、POST以外的HTTP方法,如PUT、DELETE、TRACE等

vue和springboot的解决方式

处理方式:
1、前端在遇到put/delete方法的时候,将该方法改为post方法,然后添加请求头

X-HTTP-Method-Override

,将真实的请求方式放入;
2、后端:编写过滤器,如果方法是post方法,且有

X-HTTP-Method-Override

参数的,然后重新转到对应的方法

vue

image.png

if(config.method.toLowerCase()==='put'){
    config.method ='post'
    config.headers['X-HTTP-Method-Override'] = 'put'
  }elseif(config.method.toLowerCase()==='delete'){
    config.method ='post'
    config.headers['X-HTTP-Method-Override'] = 'delete'
  }

后端

packagecom.eshore.framework.security.filter;importorg.springframework.stereotype.Component;importorg.springframework.util.StringUtils;importorg.springframework.web.bind.annotation.RequestMethod;importorg.springframework.web.filter.OncePerRequestFilter;importorg.springframework.web.filter.RequestContextFilter;importjavax.servlet.FilterChain;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletRequestWrapper;importjavax.servlet.http.HttpServletResponse;importjava.io.IOException;importjava.util.Locale;@Component//这里使用RequestContextFilter,OncePerRequestFilter有时会不生效 publicclassHttpMethodOverrideHeaderFilterextendsRequestContextFilter{privatestaticfinalString X_HTTP_METHOD_OVERRIDE_HEADER ="X-HTTP-Method-Override";@OverrideprotectedvoiddoFilterInternal(HttpServletRequest request,HttpServletResponse response,FilterChain filterChain)throwsServletException,IOException{String headerValue = request.getHeader(X_HTTP_METHOD_OVERRIDE_HEADER);if(RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())&&StringUtils.hasLength(headerValue)){String method = headerValue.toUpperCase(Locale.ENGLISH);HttpServletRequest wrapper =newHttpMethodRequestWrapper(request, method);
            filterChain.doFilter(wrapper, response);}else{
            filterChain.doFilter(request, response);}}privatestaticclassHttpMethodRequestWrapperextendsHttpServletRequestWrapper{privatefinalString method;publicHttpMethodRequestWrapper(HttpServletRequest request,String method){super(request);this.method = method;}@OverridepublicStringgetMethod(){returnthis.method;}}}
标签: spring boot 安全 http

本文转载自: https://blog.csdn.net/Think_and_work/article/details/131560312
版权归原作者 WalkerShen 所有, 如有侵权,请联系我们删除。

“springboot解决不安全的HTTP请求方式安全漏洞”的评论:

还没有评论