项目场景:
1、Spring Cloud Gateway 远程代码执行漏洞(CVE-2022-22947)
所以必须升到3.1.1
2、以spring-cloud架构做的项目
3、不想升级其他模块版本,只想升级spring-gateway
4、spring最近的漏洞怎么这么多,...心累
解决方案:
直接上步骤
第一步:pom.xml文件修改
parent改成下面的,不要依赖原来的哈
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.3</version> <relativePath/> <!-- lookup parent from repository --> </parent>
spring-cloud版本2021.0.1
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency>
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>2021.0.1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
如果gateway还调用了其他服务要加上
<!-- Feign Client for loadBalancing --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency>
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
最后的pom文件内容如下,当然如果你还有别的需要依赖也要注意版本适配哦
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!-- Feign Client for loadBalancing --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>2021.0.1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
第二步:如果原来用hystrix配置了,一定要去除哦,要用过滤器可以自己写,这里不赘述了。
default-filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallback
如果还是报了
hystrix相关错误,搜索一下看看哪里还有用么,也删除寻找其他替代方案吧。
好了现在可以启动试试了,成功修复漏洞......