【CVE-2003-1567】springboot2,禁用TRACE和TRACK方法

最近线上爆出CVE-2003-1567漏洞,经过一番查找,发现大多数介绍的都是springboot1如何禁用TRACE和TRACK方法,最后自己折腾出来了,分享一下吧`

import org.apache.catalina.Context;
 import org.apache.catalina.connector.Connector;
 import org.apache.tomcat.util.descriptor.web.SecurityCollection;
 import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
 import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
 import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;

 @Configuration
 public class TomcatConfig {
	 @Value("${server.port}")
	 private Integer port;
	 @Bean
	 public ServletWebServerFactory servletContainer() {
		 TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
			 @Override
			 protected void postProcessContext(Context context) {
				 SecurityConstraint securityConstraint = new SecurityConstraint();
				 securityConstraint.setUserConstraint("CONFIDENTIAL");
				 SecurityCollection collection = new SecurityCollection();
				 collection.addPattern("/*");
				 collection.addMethod("HEAD");
				 collection.addMethod("PUT");
				 collection.addMethod("DELETE");
				 collection.addMethod("OPTIONS");
				 collection.addMethod("TRACE");
				 collection.addMethod("COPY");
				 collection.addMethod("SEARCH");
				 collection.addMethod("PROPFIND");
				 securityConstraint.addCollection(collection);
				 context.addConstraint(securityConstraint);
			 }
		 };
		 tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector ->
			 connector.setAllowTrace(true));
		 return tomcat;
	 }
 }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值