某次云服务器漏洞扫描,发现存在Apache Tomcat HTTP请求走私漏洞(CVE-2022-42252),威胁等级高危,可以被远程利用。
根据漏洞描述可以知道是springboot内嵌tomcat的问题,解决方法也很简单,升级springboot版本或者只升级内嵌tomcat的版本,提升到一个安全的版本号上即可。
经过查看项目代码,确定了项目中使用的springboot版本号为2.5.14,而bug就存在于其所依赖tomcat-embed-core-9.0.63.jar
中,所以根据修复方案,把tomcat-embed-core
升到9.0.68
就能解决此bug。因为是通过maven构建的多模块项目,所以这里需要同时修改父子pom文件。
修改父pom文件
在父pom.xml文件的properties
节点下添加tomcat.version
属性,dependencyManagement
节点下添加tomcat-embed-core
的依赖管理,并将spring-boot-starter-tomcat
中内嵌的版本排除掉。
<properties>
<!-- 定义一个版本属性,方便后期升级使用 -->
<tomcat.version>9.0.68</tomcat.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- 从spring-boot-starter-tomcat中排除内嵌的tomcat-embed-core -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 添加指定版本的tomcat-embed-core依赖管理 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
修改子pom文件
在子pom.xml文件中添加对tomcat-embed-core
的实际依赖。
<dependencies>
<!-- 添加对tomcat-embed-core的实际依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
</dependencies>
打包重启验证
配置完以后重启springboot服务,可以看到运行的是9.0.68
版本的tomcat。
o.a.coyote.http11.Http11NioProtocol : Initializing ProtocolHandler ["http-nio-8080"]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext