钢蛋
发布于 2024-10-15 / 51 阅读
0
0

springboot项目修改内嵌tomcat版本

某次云服务器漏洞扫描,发现存在Apache Tomcat HTTP请求走私漏洞(CVE-2022-42252),威胁等级高危,可以被远程利用。

CVE-2022-42252-detail.png

根据漏洞描述可以知道是springboot内嵌tomcat的问题,解决方法也很简单,升级springboot版本或者只升级内嵌tomcat的版本,提升到一个安全的版本号上即可。

CVE-2022-42252-fixes.png

经过查看项目代码,确定了项目中使用的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


评论