springboot版本升级,及解决springsecurity漏洞问题

背景:

项目中要解决 Spring Security RegexRequestMatcher 认证绕过漏洞(CVE-2022-22978) 漏洞问题,并且需要将项目的版本整体升级到boot版本2.1.7,升级改造过程非常的痛苦,一方面对整个框架的代码不是很熟悉,另外对解决漏洞问题相对较少。

需求:

 解决Spring Security RegexRequestMatcher 认证绕过漏洞(CVE-2022-22978) 漏洞,升级boot版本2.1.7

改造前:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.gisquest.realestate</groupId><artifactId>gisqrealestate-unityplatform-core</artifactId><version>2.2.1.RELEASE</version><modules><module>unityplatform-security</module><module>unityplatform-microauth</module><module>unityplatform-apigateway</module><module>unityplatform-servicediscovery</module><module>unityplatform-microappadmin</module><module>unityplatform-apigateway-core</module><module>unityplatform-apigateway-app</module><module>unityplatform-microauth-app</module><module>unityplatform-core-comm</module></modules><packaging>pom</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><spring-boot-admin.version>1.5.6</spring-boot-admin.version><jjwt.version>0.7.0</jjwt.version><commons-lang3.version>3.3.2</commons-lang3.version><swagger2.version>2.7.0</swagger2.version><apollo-client.version>1.0.0</apollo-client.version><jackson.version>2.10.2</jackson.version><!--micro version--><micro-apigateway.version>2.2.1.RELEASE</micro-apigateway.version><micro-auth.version>2.2.1.RELEASE</micro-auth.version><micro-comm.version>2.2.1.RELEASE</micro-comm.version><micro-apigateway.img.version>2.2.RELEASE</micro-apigateway.img.version><micro-auth.img.version>2.2.RELEASE</micro-auth.img.version><micro.img.version>2.2.RELEASE</micro.img.version><com.hanweb.SecurityUtil.version>1.0</com.hanweb.SecurityUtil.version><!--XStream --><xstream.version>1.4.20</xstream.version><spring.version>5.3.20</spring.version><spring-security.version>5.5.8</spring-security.version></properties><dependencyManagement><dependencies><!--micro begin--><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-security-core</artifactId><version>${micro-auth.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityPlatform-security-app</artifactId><version>${micro-auth.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-core-comm</artifactId><version>${micro-comm.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-microauth</artifactId><version>${micro-auth.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-apigateway-core</artifactId><version>${micro-apigateway.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-apigateway</artifactId><version>${micro-apigateway.version}</version></dependency><!--micro end--><dependency><groupId>io.spring.platform</groupId><artifactId>platform-bom</artifactId><version>Brussels-SR7</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Edgware.SR2</version><type>pom</type><scope>import</scope></dependency>#### 省略##########################</dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.5.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin></plugins></build></project>

漏洞解决方案

gisqrealestate-unityplatform-core 项目下 解决Spring Security RegexRequestMatcher 认证绕过漏洞(CVE-2022-22978) 漏洞,升级boot版本2.1.7(和快速构建保持一致),注意下升级之后一些配置文件(例如redis,文件限制大小等) 和 代码 不兼容问题

漏洞影响版本

5.5.0 <= Spring Security < 5.5.7

5.6.0 <= Spring Security < 5.6.4

版本改造问题:

改造前 版本 

<spring-cloud.version>Edgware.SR2</spring-cloud.version> 
<spring-boot.version>1.5.10.RELEASE </spring-boot.version>
升级到2.x版本
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
<spring-boot.version>2.1.7.RELEASE</spring-boot.version>

问题一:项目改造前是自定义的springboot依赖,现要求去掉原先的自定义封装依赖

刚开始我是把原先自定义的springboot依赖的父依赖直接移到最外层,大概过程如下,导致出现一堆问题。

坑一:类不存在,或包不存在

但是明明可以用鼠标点击进去,此类问题经常是idea,什么缓存,或者是pom依赖下载不全导致,然后就陷入了这个误区,一直以为是idea的问题,然后idea缓存清理了很多次还是无法解决。 

然后分支代码提交后,同事检出也是同样的问题,项目还是无法启动,保错也是提示类不存在等。

此时我就怀疑可能不是idea的问题了。

后面就换了一种方式

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.10.RELEASE</version><relativePath />
</parent>

改成

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope>
</dependency>

 妈的改成这样后终于正常了,不在提示类不存在,包不存在等问题了。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><groupId>com.gisquest.realestate</groupId><artifactId>gisqrealestate-unityplatform-core</artifactId><version>2.2.1.RELEASE</version><modelVersion>4.0.0</modelVersion><packaging>pom</packaging><modules><module>unityplatform-security</module><module>unityplatform-microauth</module><module>unityplatform-apigateway</module><module>unityplatform-servicediscovery</module><module>unityplatform-microappadmin</module><module>unityplatform-apigateway-core</module><module>unityplatform-apigateway-app</module><module>unityplatform-microauth-app</module><module>unityplatform-core-comm</module></modules><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><spring-boot-admin.version>1.5.6</spring-boot-admin.version><jjwt.version>0.7.0</jjwt.version><commons-lang3.version>3.3.2</commons-lang3.version><swagger2.version>2.7.0</swagger2.version><apollo-client.version>1.0.0</apollo-client.version><jackson.version>2.10.2</jackson.version><!--micro version--><micro-apigateway.version>2.2.1.RELEASE</micro-apigateway.version><micro-auth.version>2.2.1.RELEASE</micro-auth.version><micro-comm.version>2.2.1.RELEASE</micro-comm.version><micro-apigateway.img.version>2.2.RELEASE</micro-apigateway.img.version><micro-auth.img.version>2.2.RELEASE</micro-auth.img.version><micro.img.version>2.2.RELEASE</micro.img.version><com.hanweb.SecurityUtil.version>1.0</com.hanweb.SecurityUtil.version><!--XStream --><xstream.version>1.4.19</xstream.version><spring-cloud.version>Greenwich.SR2</spring-cloud.version><spring-boot.version>2.1.7.RELEASE</spring-boot.version><eureka.version>2.1.0.RELEASE</eureka.version><openfeign.version>2.0.0.RELEASE</openfeign.version><zuul.version>2.1.2.RELEASE</zuul.version><commons-lang.version>2.6</commons-lang.version><commons-collections.version>3.2.2</commons-collections.version><commons-beanutils.version>1.9.3</commons-beanutils.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency><!--micro begin--><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-security-core</artifactId><version>${micro-auth.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityPlatform-security-app</artifactId><version>${micro-auth.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-core-comm</artifactId><version>${micro-comm.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-microauth</artifactId><version>${micro-auth.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-apigateway-core</artifactId><version>${micro-apigateway.version}</version></dependency><dependency><groupId>com.gisquest.realestate</groupId><artifactId>unityplatform-apigateway</artifactId><version>${micro-apigateway.version}</version></dependency><!--micro end--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId><version>${eureka.version}</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>${openfeign.version}</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-zuul</artifactId><version>${zuul.version}</version></dependency></project>

坑二:idea中maven设置,最好调整成maven运行

否则会出现稀奇古怪的问题,比如上面的之前用parent依赖方式我本地可以跑(奇了怪),但是同事拉下拉却跑不了,切换成eclipse也同样项目跑不起来。

经过一番折腾代码是跑起来了总算不提示类不存等问题。

代码兼容问题

org.springframework.data.redis.serializer.SerializationException: Cannot deserialize

org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.InvalidClassException: org.springframework.security.core.authority.SimpleGrantedAuthority; local class incompatible: stream classdesc serialVersionUID = 420, local class serialVersionUID = 510
    at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:84) ~[spring-data-redis-2.1.10.RELEASE.jar!/:2.1.10.RELEASE]

问题二:alibaba.fastjson.JSONObject cannot be cast to xx

java.lang.ClassCastException: com.alibaba.fastjson.JSONObject cannot be cast to com.gisquest.realestate.security.validate.code.ValidateCode

@Overridepublic ValidateCode get(ServletWebRequest request, ValidateCodeType validateCodeType) {Object object = redisTemplate.opsForValue().get(buildKey(request, validateCodeType));if (object == null) {return null;}return (ValidateCode)object ;}

改造后

@Overridepublic ValidateCode get(ServletWebRequest request, ValidateCodeType validateCodeType) {Object object = redisTemplate.opsForValue().get(buildKey(request, validateCodeType));if (object == null) {return null;}String josn =JSON.toJSONString(object);return JSONObject.parseObject(josn,ValidateCode.class);}

问题解决!!!!

问题三:   升级后通过feign调用认证服务接口/oauth/check_token接口提示如下 Illegal hexadecimal character - at index 8
 

org.apache.commons.codec.DecoderException: Illegal hexadecimal character - at index 8
    at org.apache.commons.codec.binary.Hex.toDigit(Hex.java:286)
    at org.apache.commons.codec.binary.Hex.decodeHex(Hex.java:106)
    at com.gisquest.realestate.utils.Encodes.decodeHex(Encodes.java:41)

原因版本问题

改造前spring-security-core-4.2.4.RELEASE

在AbstractUserDetailsAuthenticationProvider在实现类中additionalAuthenticationChecks方法逻辑如下

	protected void additionalAuthenticationChecks(UserDetails userDetails,UsernamePasswordAuthenticationToken authentication)throws AuthenticationException {Object salt = null;if (this.saltSource != null) {salt = this.saltSource.getSalt(userDetails);}if (authentication.getCredentials() == null) {logger.debug("Authentication failed: no credentials provided");throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials","Bad credentials"));}String presentedPassword = authentication.getCredentials().toString();if (!passwordEncoder.isPasswordValid(userDetails.getPassword(),presentedPassword, salt)) {logger.debug("Authentication failed: password does not match stored value");throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials","Bad credentials"));}}

改造后

spring-security-core-5.1.6.RELEASE版本中AbstractUserDetailsAuthenticationProvider在实现类中改方法additionalAuthenticationChecks

   protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {if (authentication.getCredentials() == null) {this.logger.debug("Authentication failed: no credentials provided");throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));} else {String presentedPassword = authentication.getCredentials().toString();if (!this.passwordEncoder.matches(presentedPassword, userDetails.getPassword())) {this.logger.debug("Authentication failed: password does not match stored value");throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));}}}

   逻辑变化了

使用了自定义的密码加密类

 密码加密方式发现不一样了,因此按照原先代码逻辑获取到的前后密码其实是一样的,但是升级后GisqPasswordEncoder起了作用,因此在比较时应该时加密后的匹配

因此改成这样

问题四:feign调用token校验接口,在项目中未搜索到,

后来打断点才发现竟然后spring-security-oaruth2包内部类CheckTokenEndpoint中的接口,无语,我还以为是自己定义的呢找了半天未找打!!!!!

jar包依赖冲突问题:

方式一:选择依赖的模块,鼠标右键,选择show dependency

,如果有冲突会出现报红!!!

方式二:安装一个maven-helper插件

如果有冲突会自动显示,然后去排处即可

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/671154.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【云原生】Pod 的生命周期(一)

【云原生】Pod 的生命周期&#xff08;一&#xff09;【云原生】Pod 的生命周期&#xff08;二&#xff09; Pod 的生命周期&#xff08;一&#xff09; 1.Pod 生命期2.Pod 阶段3.容器状态3.1 Waiting &#xff08;等待&#xff09;3.2 Running&#xff08;运行中&#xff09;3…

《第一行代码》第二版学习笔记(8)——网络技术

文章目录 一、Http1、HttpURLConnection2、OKHttp 二、解析JSON格式数据1、使用JSONObject2、使用GSON解析JSON数据 一、Http 1、HttpURLConnection public void run() {HttpURLConnection connection null;BufferedReader reader null;try {URL url new URL("http://…

LangChain框架学习总结

目录 一、简介 二、概念 三、组件具体介绍 3.1 Models 3.1.1 LLMs 3.1.2 Chat Models 3.1.3 Text Embedding Modesl 3.1.4 总结 3.2 Prompts 3.2.1 LLM Prompt Template 3.2.1.1 自定义PromptTemplate 3.2.1.2 partial PromptTemplate 3.2.1.3 序列化PromptTemplat…

24.5.5(离散化+树状数组,线段树)

星期一&#xff1a; dp题单 背包 第四题 混可乐 cf传送门 思路&#xff1a;条件可演化为每种可乐值为 ai-n&#xff0c;选最少的可乐使总和为0&#xff08;具体可看官方题解 到这会发现背包并不适合了&#xff0c;其实这是道bfs伪装的背包…

Unity3D DOTween

简单介绍一下 DOTween 插件的使用。 导入插件 先到 Asset Store 获取 DOTween 插件&#xff0c;然后在 Package Manager 的 My Assets 中搜索&#xff0c;下载并导入插件。 导入后&#xff0c;会自动弹出一个窗口&#xff0c;提示需要先对插件进行配置。 点击上图中的按钮&am…

【Osek网络管理测试】[TG3_TC5]等待总线睡眠状态_1

&#x1f64b;‍♂️ 【Osek网络管理测试】系列&#x1f481;‍♂️点击跳转 文章目录 1.环境搭建2.测试目的3.测试步骤4.预期结果5.测试结果 1.环境搭建 硬件&#xff1a;VN1630 软件&#xff1a;CANoe 2.测试目的 验证DUT在满足进入等待睡眠状态的条件时是否进入该状态 …

【漏洞复现】某小日子太阳能系统DataCube3审计

漏洞描述 某小日子太阳能系统DataCube3终端测量系统 多个漏洞利用方式 免责声明 技术文章仅供参考,任何个人和组织使用网络应当遵守宪法法律,遵守公共秩序,尊重社会公德,不得利用网络从事危害国家安全、荣誉和利益,未经授权请勿利用文章中的技术资料对任何计算机系统进…

【简单介绍下7-Zip】

&#x1f3a5;博主&#xff1a;程序员不想YY啊 &#x1f4ab;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f917;点赞&#x1f388;收藏⭐再看&#x1f4ab;养成习惯 ✨希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出…

产业空间集聚DO指数计算

1.前言 创始人 :Duranton and Overman&#xff08;2005&#xff09; 目前应用较多的产业集聚度量指数主要基于两类&#xff0c;一是根据不同空间地理单元中产业经济规模的均衡性进行构造&#xff0c;如空间基尼系数与EG指数&#xff1b;二是基于微观企业地理位置信息形成的产业…

FR-TSN4206获得“时间敏感网络产业链名录计划”测试认证证书,TSN交换机助力智能工业发展

TSN技术&#xff0c;即时间敏感网络技术&#xff0c;已成为智能工业、自动驾驶等领域的核心。它通过时钟同步、数据调度等功能&#xff0c;确保低延迟、高可靠性的数据传输。 为推动TSN技术在我国的发展&#xff0c;工业互联网产业联盟联合多家单位启动了“时间敏感网络产业链名…

Vue-router使用(配置路径、路由跳转、相关API、多级路由、路由守卫,两种工作模式)

Vue-router使用(配置路径、路由跳转、相关API、多级路由、路由守卫&#xff0c;两种工作模式) 目录 Vue-router使用(配置路径、路由跳转、相关API、多级路由、路由守卫&#xff0c;两种工作模式)安装配置路径路由跳转不携带参数跳转携带参数跳转?形式携带参数地址中直接携带参…

【LeetCode 121】买卖股票的最佳时机

思路 思路&#xff1a; 所谓代码的复杂性来源于业务的复杂性&#xff0c;如果能够想清楚业务实现逻辑&#xff0c;就能够轻松写出代码&#xff1b; 假设当前是第i天&#xff0c;如何在第i天赚到最多的钱&#xff1f;需要在第i天之前以最低价买入股票&#xff1b; 所以需要求…