Spring 官方修复零日漏洞,推出 Spring Boot 2.6.6、2.5.12 等新版本
一、漏洞说明
这个漏洞还要从 3 月 29 日晚间说起。
彼时有不少网友爆料,Spring 框架出现“史诗级” RCE 漏洞,平地一声雷,一时之间,快要入睡的开发者们纷纷坐起查看关于漏洞的情况,闹得技术圈中人心惶惶。
不过有些不同寻常的是,这个漏洞并没有像 Log4j2 事件那样引起圈内诸多企业大厂的紧急行动,甚至连国外披露漏洞的根源也是来自 QQ 和国内部分网络安全网站。
这也让不少网友猜测,该漏洞应该是国内某个安全机构、安全人员最先发现的。
果不其然,据 3 月 31 日国家信息安全漏洞共享平台(CNVD)发布的《关于Spring框架存在远程命令执行漏洞的安全公告》显示,这群神秘的白帽子们包括蚂蚁科技集团、奇安信科技、杭州安恒信息技术、安天科技、360、北京天融信,当然这些都是后话了。
1.1 Spring 零日漏洞真的存在
就在开发者越来越焦灼时,Spring.io 官方于 3 月 31 日晚间出面证实了这一漏洞的存在,并带来了解决方案。
根据公告,我们发现这个漏洞的影响远比我们想象的更为严重,如果满足以下几种门槛,极有可能受漏洞影响:
-
JDK 9 或更高版本
-
Apache Tomcat 作为 Servlet 容器
-
打包为传统的 WAR(与 Spring Boot 可执行 jar 相比)
-
spring-webmvc 或 spring-webflux 依赖
-
Spring Framework 版本 5.3.0 到 5.3.17、5.2.0 到 5.2.19 以及更早的版本
二、官方更新
2.1 初步解决方案
当前 Spring.io 已经发布了 Spring Framework 5.3.18 和 5.2.20 版本,同时还带来了最新的依赖于 Spring Framework 5.3.18 的 Spring Boot 2.6.6 和 2.5.12 。因为如果你能升级到 Spring Framework 5.3.18 和 5.2.20,就不用以下的修复方案了。
如果不可以,Spring 官方建议通过 @ControllerAdvice 来设置 WebDataBinder 的 disallowedFields。
@ControllerAdvice
@Order(Ordered.LOWEST_PRECEDENCE)
public class BinderControllerAdvice {
@InitBinder
public void setAllowedFields(WebDataBinder dataBinder) {
String denylist = new String{"class.*", "Class.*", "*.class.*", "*.Class.*"};
dataBinder.setDisallowedFields(denylist);
}
}
这个解决方案通常会有效,但也并不是 100% 可以阻止漏洞。因此为了更加保险一些,Spring.io 还建议应用程序可以扩展
RequestMappingHandlerAdapter,同时在所有其他初始化之后,在最后更新WebDataBinder。为了实现这一点,Spring Boot 应用程序可以声明一个 WebMvcRegistrations(Spring MVC)或 WebFluxRegistrations bean(Spring WebFlux)。
在Spring MVC中(在WebFlux中也类似)示例如下:
package vip.mate.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.annotation.InitBinderDataBinderFactory; import org.springframework.web.method.support.InvocableHandlerMethod; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.ServletRequestDataBinderFactory; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } @Bean public WebMvcRegistrations mvcRegistrations() { return new WebMvcRegistrations() { @Override public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() { return new ExtendedRequestMappingHandlerAdapter(); } }; } private static class ExtendedRequestMappingHandlerAdapter extends RequestMappingHandlerAdapter { @Override protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> methods) { return new ServletRequestDataBinderFactory(methods, getWebBindingInitializer()) { @Override protected ServletRequestDataBinder createBinderInstance(Object target, String name, NativeWebRequest request) throws Exception { ServletRequestDataBinder binder = super.createBinderInstance(target, name, request); String[] fields = binder.getDisallowedFields(); List<String> fieldList = new ArrayList<>(fields != null ? Arrays.asList(fields) : Collections.emptyList()); fieldList.addAll(Arrays.asList("class.*", "Class.*", "*.class.*", "*.Class.*")); binder.setDisallowedFields(fieldList.toArray(new String[]{})); return binder; } }; } } }
对于没有 Spring Boot 的 Spring MVC,应用程序可以从 @EnableWebMvc 切换到直接扩展
DelegatingWebMvcConfiguration,如这个文档中(https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-config-advanced-java)高级配置部分所述,然后重写 createRequestMappingHandlerAdapter 方法。
基于以上,我们建议受漏洞影响的产品(服务)厂商和信息系统运营者第一时间进行自查,并及时升级至最新版本。

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
前沿科技探究之AI功能:慢SQL发现
SQLdiag:慢SQL发现 SQLdiag是openGauss中SQL语句执行时长预测工具。现有的预测技术主要基于执行计划的预测方法,但这些预测方案仅适用于OLAP场景且可以获取执行计划的任务,对于OLTP或者HTAP这样的快速、简单查询是没有太多使用价值的。与上述方案不同,SQLdiag着眼于数据库的历史SQL语句,通过对历史SQL语句的执行表现进行总结归纳,将之再用于推断新的未知业务上。由于短时间内数据库SQL语句执行时长不会有太大的差距,SQLdiag可以从历史数据中检测出与已执行SQL语句相似的语句结果集,并基于SQL向量化技术和模板化方法预测SQL语句执行时长。本工具有如下优点: 不需要SQL语句的执行计划,对数据库性能不会有任何的影响。 使用场景广泛,目前业内的很多算法局限性比较高,比如只适用于OLTP或者OLAP,而SQLdiag使用场景广泛。 该框架容易理解,只需要简单的操作,就可以训练出自己的预测模型。 本工具的典型应用场景是对一批即将上线的SQL语句进行透视,提前识别风险。 概述 SQLdiag是一个SQL语句执行时间预测工具,通过模板化方法或者深度学习方法,实现...
- 下一篇
layui-vue 1.0.0 发布,基于 vue 3.0 的桌面端组件库
官网:http://www.layui-vue.com 仓库:https://gitee.com/layui-vue/layui-vue 更新内容: [重要] 修订 version 为 1.0.0。 [新增] empty 组件 extra 插槽, 支持扩展内容。 [新增] result 组件 extra 插槽, 支持扩展内容。 [新增] exception 组件 extra 插槽, 支持扩展内容。 [新增] switch 组件 onswitch-value 属性, 默认为 true。 [新增] switch 组件 unswitch-value 属性, 默认为 false。 [新增] date-picker 组件 time 属性, 支持 时 分 秒 选择。 [新增] date-picker 组件 yearmonth 属性, 支持 年 月 选择。 [新增] tab 组件 position 属性, 用于支持不同方向的选项卡标题。 [修复] date-picker 组件 type 属性为 time 时, v-model 默认不生效。 [修复] date-picker 组件 12 小时制为 24...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Hadoop3单机部署,实现最简伪集群
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS关闭SELinux安全模块