最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot版本升級以及解決springsecurity漏洞的問題

 更新時間:2024年08月14日 10:01:53   作者:喜羊羊love紅太狼  
這篇文章主要介紹了springboot版本升級以及解決springsecurity漏洞的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

背景

項目中要解決 Spring Security RegexRequestMatcher 認(rèn)證繞過漏洞(CVE-2022-22978) 漏洞問題,并且需要將項目的版本整體升級到boot版本2.1.7,升級改造過程非常的痛苦,一方面對整個框架的代碼不是很熟悉,另外對解決漏洞問題相對較少。

需求

解決Spring Security RegexRequestMatcher 認(rèn)證繞過漏洞(CVE-2022-22978) 漏洞,升級boot版本2.1.7

改造前父pom如下(部分依賴省略):

<?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>
 
			<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>
</project>

漏洞解決方案

gisqrealestate-unityplatform-core 項目下 解決Spring Security RegexRequestMatcher 認(rèn)證繞過漏洞(CVE-2022-22978) 漏洞

升級boot版本2.1.7(和快速構(gòu)建保持一致)

注意下升級之后一些配置文件(例如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依賴,現(xiàn)要求去掉原先的自定義封裝依賴

剛開始我是把原先自定義的springboot依賴的父依賴直接移到最外層,大概過程如下,導(dǎo)致出現(xiàn)一堆問題。

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

項目中出現(xiàn)大量的類不存在,但是明明可以用鼠標(biāo)點(diǎn)擊進(jìn)去,此類問題經(jīng)常是idea,什么緩存,或者是pom依賴下載不全導(dǎo)致,然后就陷入了這個誤區(qū),一直以為是idea的問題。

先是清理 idea緩存、執(zhí)行mvn 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>
 
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
 
	 
</project>

坑二:idea中maven設(shè)置,最好調(diào)整成maven運(yùn)行(推薦)

否則會出現(xiàn)稀奇古怪的問題,比如上面的之前用parent依賴方式我本地可以跑(奇了怪),但是同事拉下拉卻跑不了,切換成eclipse也同樣項目跑不起來。

經(jīng)過一番折騰代碼是跑起來了總算不提示類不存等問題。

代碼兼容問題

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]

解決方法:

redis跨版本升級后,需要把redis緩存清理一下

問題一: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

  • 改造前邏輯
     @Override
    public ValidateCode get(ServletWebRequest request, ValidateCodeType validateCodeType) {
        Object object = redisTemplate.opsForValue().get(buildKey(request, validateCodeType));
        if (object == null) {
            return null;
        }
   
        return (ValidateCode)object ;
    }
  • 改造后
    @Override
    public 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調(diào)用認(rèn)證服務(wù)接口/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在實(shí)現(xiàn)類中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在實(shí)現(xiàn)類中改方法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"));
            }
        }
    }

邏輯變化了

使用了自定義的密碼加密類

密碼加密方式發(fā)現(xiàn)不一樣了,因此按照原先代碼邏輯獲取到的前后密碼其實(shí)是一樣的,但是升級后GisqPasswordEncoder起了作用,因此在比較時應(yīng)該時加密后的匹配

因此改成這樣

問題三:feign調(diào)用token校驗接口,在項目中未搜索到

后來打斷點(diǎn)才發(fā)現(xiàn)竟然后spring-security-oaruth2包內(nèi)部類CheckTokenEndpoint中的接口,無語,我還以為是自己定義的呢找了半天未找打!?。。?!

jar包依賴沖突問題

方式一:選擇依賴的模塊,鼠標(biāo)右鍵,選擇show dependency

如果有沖突會出現(xiàn)報紅?。?!

方式二:安裝一個maven-helper插件

如果有沖突會自動顯示,然后去排處即可

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot如何實(shí)現(xiàn)starter原理詳解

    SpringBoot如何實(shí)現(xiàn)starter原理詳解

    這篇文章主要介紹了SpringBoot如何實(shí)現(xiàn)starter原理詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • IntelliJ?IDEA安裝與基礎(chǔ)配置指南

    IntelliJ?IDEA安裝與基礎(chǔ)配置指南

    IntelliJ?IDEA是一款由JetBrains公司開發(fā)的Java集成開發(fā)環(huán)境,支持Java、Kotlin、Groovy、Scala等多種編程語言,IntelliJ?IDEA作為一款強(qiáng)大的開發(fā)工具,被廣泛應(yīng)用于Java開發(fā)、Web開發(fā)、Android開發(fā)等領(lǐng)域,本文給大家介紹了IntelliJ?IDEA安裝與基礎(chǔ)配置
    2025-07-07
  • 使用Java實(shí)現(xiàn)簽字功能的示例代碼

    使用Java實(shí)現(xiàn)簽字功能的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何使用Java實(shí)現(xiàn)簽字功能,同時支持將簽字圖像保存為PNG格式和將簽字添加到PDF文檔中,感興趣的可以了解下
    2024-02-02
  • Java List集合返回值去掉中括號(''[ ]'')的操作

    Java List集合返回值去掉中括號(''[ ]'')的操作

    這篇文章主要介紹了Java List集合返回值去掉中括號('[ ]')的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • mybatis-plus 攔截器敏感字段加解密的實(shí)現(xiàn)

    mybatis-plus 攔截器敏感字段加解密的實(shí)現(xiàn)

    數(shù)據(jù)庫在保存數(shù)據(jù)時,對于某些敏感數(shù)據(jù)需要脫敏或者加密處理,本文主要介紹了mybatis-plus 攔截器敏感字段加解密的實(shí)現(xiàn),感興趣的可以了解一下
    2021-11-11
  • MyBatis 結(jié)果映射的兩種方式

    MyBatis 結(jié)果映射的兩種方式

    本文主要介紹了MyBatis的結(jié)果映射機(jī)制,包括基本結(jié)果映射、復(fù)雜結(jié)果映射以及動態(tài)結(jié)果映射和延遲加載,通過合理配置結(jié)果映射,可以簡化復(fù)雜查詢結(jié)果,感興趣的可以了解一下
    2024-11-11
  • log4j2采用AsyncLogger出現(xiàn)的錯誤及解決方案

    log4j2采用AsyncLogger出現(xiàn)的錯誤及解決方案

    這篇文章主要介紹了log4j2采用AsyncLogger出現(xiàn)的錯誤及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • java中l(wèi)ist的用法和實(shí)例講解

    java中l(wèi)ist的用法和實(shí)例講解

    這篇文章主要介紹了java中l(wèi)ist的用法和實(shí)例講解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • java中URLEncoder.encode與URLDecoder.decode處理url特殊參數(shù)的方法

    java中URLEncoder.encode與URLDecoder.decode處理url特殊參數(shù)的方法

    這篇文章主要給大家介紹了關(guān)于java中URLEncoder.encode與URLDecoder.decode處理url特殊參數(shù)的方法,文中介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-03-03
  • 使用lombok注解導(dǎo)致mybatis-plus TypeHandler失效的解決

    使用lombok注解導(dǎo)致mybatis-plus TypeHandler失效的解決

    這篇文章主要介紹了使用lombok注解導(dǎo)致mybatis-plus TypeHandler失效的解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07

最新評論

沁源县| 灌阳县| 永顺县| 易门县| 龙州县| 大同县| 博爱县| 秭归县| 皋兰县| 静海县| 屯昌县| 长春市| 白玉县| 拉孜县| 周宁县| 岳西县| 顺昌县| 洛扎县| 久治县| 张家港市| 江源县| 吉林省| 龙口市| 承德县| 介休市| 罗山县| 包头市| 巴中市| 巴彦淖尔市| 综艺| 盈江县| 四平市| 株洲县| 赤水市| 三都| 京山县| 芷江| 富宁县| 张北县| 中方县| 高密市|