redission 升版后引发的问题

文章目录

背景

代码漏洞扫描,发现 redisson 版本有漏洞

CVE:CVE-2023-42809
有问题的 jar 包:redisson-spring-boot-starter-3.17.3.jar

于是上网找漏洞解决方案,参考文档:https://nvd.nist.gov/vuln/detail/CVE-2023-42809

Redisson is a Java Redis client that uses the Netty framework. Prior to version 3.22.0, some of the messages received from the Redis server contain Java objects that the client deserializes without further validation. Attackers that manage to trick clients into communicating with a malicious server can include especially crafted objects in its responses that, once deserialized by the client, force it to execute arbitrary code. This can be abused to take control of the machine the client is running in. Version 3.22.0 contains a patch for this issue. Some post-fix advice is available. Do NOT use Kryo5Codec as deserialization codec, as it is still vulnerable to arbitrary object deserialization due to the setRegistrationRequired(false) call. On the contrary, KryoCodec is safe to use. The fix applied to SerializationCodec only consists of adding an optional allowlist of class names, even though making this behavior the default is recommended. When instantiating SerializationCodec please use the SerializationCodec(ClassLoader classLoader, Set<String> allowedClasses) constructor to restrict the allowed classes for deserialization.

简单来说就是 3.22.0 版本包含此问题的修补程序
于是升级依赖

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-spring-boot-starter</artifactId>
    <version>${redisson.version}</version>
</dependency>

本地运行正常,结果到线上就报错了

Caused by: java.lang.ClassNotFoundException: org.springframework.data.redis.connection.zset.Tuple
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
… 30 common frames omitted

好吧,开始排查
 

排查

方向1:线上环境和本地环境
线上用的 docker 是 open-jdk,本地用的是普通 jdk
于是下载了 open-jdk,测试发现没有问题,下载地址 :https://mirrors.tuna.tsinghua.edu.cn/Adoptium/

方向2:启动命令
线上启动命令和idea的启动命令不一样,逐个排除后,发现idea加了 -noverify
百度了一下 -noverify 的含义

-noverify 是 Java 虚拟机(JVM)的一个启动参数,用于禁用字节码验证。字节码验证是 JVM 在加载类的过程中执行的一个重要步骤,用于确保字节码的安全性和正确性。通过字节码验证,JVM可以检查字节码是否符合Java虚拟机规范,以避免潜在的安全漏洞和错误。
当使用 -noverify 参数启动 Java 应用程序时,JVM 将跳过字节码验证阶段,这可能会带来一些潜在的风险和副作用,包括但不限于:
1:由于跳过了字节码验证,恶意代码可能会更容易地被加载和执行,从而增加了安全漏洞的风险。
2:字节码验证是确保代码安全性和正确性的重要步骤,跳过这一步可能会导致潜在的运行时错误,从而影响应用程序的性能和稳定性。
3:某些应用程序可能依赖于字节码验证来确保代码的正确性,因此禁用字节码验证可能导致应用程序出现意外行为或错误。
通常情况下,不建议在生产环境中使用 -noverify 参数,除非您明确了解其潜在风险并且有充分的理由需要禁用字节码验证。在开发和调试过程中,有时会使用 -noverify 参数来加快启动时间,但在生产环境中应该避免使用。

简单来说就是线上不能用 -noverify,因为不安全

方向3:redission 和 springboot 的版本不兼容
问题根本原因就是这个

 

解决

可以看到 redisson-spring-boot-starter 版本 3.22.0 里面的 redisson-spring-data 是 redisson-spring-data-31

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-spring-data-31</artifactId>
    <version>${project.version}</version>
</dependency>

但项目的 springboot 版本用的是 2.7.18,所以要使用 redisson-spring-data-27,参考文档:https://github.com/redisson/redisson/tree/master/redisson-spring-data

解决思路,排除 redisson-spring-data-31,引入 redisson-spring-data-27

解决后的依赖

<redisson.version>3.22.0</redisson.version>
     
<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-spring-boot-starter</artifactId>
    <version>${redisson.version}</version>

</dependency>

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-spring-data-27</artifactId>
    <version>${redisson.version}</version>
</dependency>
  • 22
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Spring Boot 2.3.0 对应的 Redisson 版本是 3.12.5。你可以在 Spring Boot 官方文档中查看更多关于 Spring Boot 2.3.0 的信息。同时,Redisson 的官方文档中也提供了 Redisson 版本与 Spring Boot 版本之间的对应关系。建议在集成 Redisson 时,选择与你使用的 Spring Boot 版本兼容的 Redisson 版本。 ### 回答2: Spring Boot 2.3.0版本对应的Redisson版本是3.12.3。 Redisson是一个基于RedisJava驻内存数据网格(In-Memory Data Grid)和分布式计算框架,简化了对分布式数据结构和服务的访问和操作。它提供了多种并发的集合数据结构,如Map、Set、Queue等,并且支持分布式锁和分布式AtomicLong等功能。 在Spring Boot项目中使用Redisson作为Redis的客户端,可以方便地访问和操作Redis服务。Spring Boot 2.3.0版本集成了Redisson 3.12.3作为默认的Redis客户端版本。我们可以直接在pom.xml文件中引入Redisson的依赖,并进行相应的配置,即可使用Redisson连接和操作Redis。 在使用Spring Boot版本为2.3.0的项目中,如果想使用Redisson,可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> <version>3.12.3</version> </dependency> ``` 然后,在application.properties(或application.yml)文件中配置Redisson的连接信息,如Redis的地址、端口、密码等。配置完毕后,就可以在Spring Boot项目中使用Redisson进行对Redis的访问和操作了。 需要注意的是,Redisson的版本与Spring Boot的版本可能不完全一致,因此在实际使用中,可以根据项目需求选择适合的Redisson版本。 ### 回答3: Spring Boot 2.3.0 对应的 Redisson 版本是 3.12.2。在 Spring Boot 2.3.0 中,Redisson 客户端库通过 Maven 的依赖管理工具进行版本的控制。在 pom.xml 文件中引入 Redisson 的依赖项,并指定版本为 3.12.2,即可使用 Redisson 客户端库的功能。 Redisson 是一个基于 Redis 的分布式 Java 对象和服务框架,它提供了丰富的功能和易于使用的 API,可以方便地与 Redis 数据库进行交互。Redisson 使用了高级的数据结构和算法来优化 Redis 的性能,并提供了分布式的锁、并发处理、分布式对象等功能,使得开发者可以更加方便地使用 Redis 构建分布式应用。 Spring Boot 是一个用于开发独立的、基于生产级别的 Spring 应用程序的框架。它提供了各种扩展和集成,使得开发者能够快速构建可扩展、高性能的应用程序。Spring Boot 2.3.0 版本是其中一个版本,它引入了许多新的功能和改进,并且对 Redisson 客户端库的支持也进行了更新,以保持与 Redisson 的版本兼容。 总结来说,Spring Boot 2.3.0 版本对应的 Redisson 版本是 3.12.2。开发者可以通过在项目的 pom.xml 文件中添加 Redisson 的依赖项,并指定版本为 3.12.2,来使用 Redisson 客户端库的功能。这样可以方便地与 Redis 数据库进行交互,并实现各种分布式应用的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值