Browse Source

禁止TRACE请求

pull/54/MERGE
陈精华 2 years ago
parent
commit
f0dc845825
No known key found for this signature in database
GPG Key ID: 30BDC970902B755D
  1. 30
      server/src/main/java/cn/keking/web/filter/SecurityFilterProxy.java

30
server/src/main/java/cn/keking/web/filter/SecurityFilterProxy.java

@ -0,0 +1,30 @@
package cn.keking.web.filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Configuration
public class SecurityFilterProxy extends OncePerRequestFilter {
private String NOT_ALLOW_METHODS = "TRACE";
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if((","+NOT_ALLOW_METHODS+",").indexOf(","+request.getMethod().toLowerCase()+",") > -1) {
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
response.setHeader("Content-Type", "text/html; charset=iso-8859-1");
response.getWriter().println("Method Not Allowed");
return;
}
super.doFilter(request, response, filterChain);
}
}
Loading…
Cancel
Save