项目框架升级:Spring Boot 升级到2.6.5, Spring Framework升级到5.3.18
接到安全漏洞扫描的通知:Spring Boot 集成环境信息泄露漏洞【POC】
处置建议:Spring 官方已发布漏洞修复版本,请用户及时更新至最新版本。
https://github.com/spring-projects/spring-framework/tags
安全版本:
Spring Framework == 5.3.18
Spring Framework == 5.2.20
我检查了项目当前的框架版本:
12 6 7org.springframework.boot 3spring-boot-starter-parent 42.3.9.RELEASE 58 5.2.13.RELEASE 9 ...... 10
妥妥地命中,必须要整改。
一、升级框架依赖
无论如何,安全是第一,所以先把框架升级再说。(具体是选择哪个版本升级,建议按照安全厂商的要求)
12 6 7 8org.springframework.boot 3spring-boot-starter-parent 42.6.5 59 5.3.18 102.6.5 112.6.3 12 ...... 13
JDK使用corretto-1.8.0_322
框架依赖升级了之后,开始编译调试,也就是升级框架带来的兼容性问题,通常最令人抓狂的也就是这部分。
二、调试基础框的兼容性问题
不断地发现报错有各种问题,网上找类似的情况,再分析、筛选、尝试,将搜罗的解决方法记录下来。
1.RedisCacheWriter错误
先把升级后接口新加的3个方法添加上,后续有问题再调试。
1 @Override 2 public void clearStatistics(String name) { 3 statistics.reset(name) ; 4 } 5 6 @Override 7 public RedisCacheWriter withStatisticsCollector(CacheStatisticsCollector cacheStatisticsCollector){ 8 return this; 9 } 10 11 @Override 12 public CacheStatistics getCacheStatistics(String cacheName) { 13 return statistics.getCacheStatistics(cacheName); 14 }
在该类头部,添加定义:
1 private final CacheStatisticsCollector statistics = CacheStatisticsCollector.create();
2.RedisUtil错误
(1)替换报错的方法
1 private Setkeys(String keyPrefix) { 2 String realKey = keyPrefix + "*"; 3 4 try { 5 return redisTemplate.execute((RedisCallback >) connection -> { 6 Set binaryKeys = new HashSet<>(); 7 8 Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().match(realKey).count(Integer.MAX_VALUE).build()); 9 while (cursor.hasNext()) { 10 binaryKeys.add(new String(cursor.next())); 11 } 12 13 return binaryKeys; 14 }); 15 } catch (Throwable e) { 16 e.printStackTrace(); 17 } 18 19 return null; 20 }
(2)报错语句加上类型转换
1 @SuppressWarnings("unchecked") 2 public void del(String... key) { 3 if (key != null && key.length > 0) { 4 if (key.length == 1) { 5 redisTemplate.delete(key[0]); 6 } else { 7 redisTemplate.delete((Collection) CollectionUtils.arrayToList(key)); 8 } 9 } 10 }
3.无法访问okhttp3.HttpUrl
1 private static MinioClient initMinio(String minioUrl, String minioName,String minioPass) { 2 if (minioClient == null) { 3 try { 4 minioClient = MinioClient.builder() 5 .endpoint(minioUrl) 6 .credentials(minioName, minioPass) 7 .build(); 8 } catch (Exception e) { 9 e.printStackTrace(); 10 } 11 } 12 return minioClient; 13 }
分析原因:项目里的依赖包版本冲突,修改pom.xml
12 5 6 78.3.7 34.8.1 48 ...... 9 10 15 16io.minio 11minio 12${minio.version} 13compile 1417 22 ...... 23com.squareup.okhttp3 18okhttp 19${okhttp.version} 20compile 21
4.程序包feign.hystrix不存在
添加依赖引用:
12 3 4 7 ...... 8org.springframework.cloud 5spring-cloud-starter-openfeign 69 12io.github.openfeign 10feign-hystrix 11
5.程序包org.springframework.cloud.netflix.ribbon不存在
12 org.springframework.cloud 3spring-cloud-openfeign-core 43.1.1 5compile 6
检查项目里的依赖包版本冲突问题
6.程序包org.junit不存在
12 junit 3junit 44.13.2 5test 6
7.对RemoteApplicationEvent的引用不明确
1 public JeecgRemoteApplicationEvent(EventObj source, String originService) { 2 super(source, originService, (String) null); 3 this.eventObj = source; 4 }
8.dependencies.dependency.version
1 [INFO] Scanning for projects... 2 [ERROR] [ERROR] Some problems were encountered while processing the POMs: 3 [ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-netflix-hystrix:jar is missing. @ line 51, column 21 4 @ 5 [ERROR] The build could not read 1 project -> [Help 1]
注明依赖包的版本号:
12 org.springframework.cloud 3spring-cloud-starter-netflix-hystrix 42.2.10.RELEASE 5compile 6
9.解决其他一些依赖包的引用与版本冲突问题,在此就不一一列举
Cannot resolve io.github.openfeign:feign-hystrix:11.8
Cannot resolve org.springframework.boot:spring-boot-configuration-processor:2.6.5
Cannot resolve org.springframework.cloud:spring-cloud-starter-openfeign:3.1.1
Cannot resolve io.netty:netty-all:4.1.75.Final
Cannot resolve org.codehaus.groovy:groovy:3.0.10
10.项目编译通过,检查框架是否升级成功,并且不存在其他版本冲突
(1)如图:Spring Framework == 5.3.18
(2)如图:Spring Boot== 2.6.5
注:看到以上2个图中的版本与预期一致,说明框架升级编译已没问题,后续再对业务代码进行调试、试运行。