spring - Spring RCE漏洞(CVE-2022-22965)如何解决?

标签 spring spring-boot spring-mvc security spring-webflux

更新

此问题现已分配给 CVE-2022-22965 .除了以下不错的答案,请检查Spring Framework RCE: Early Announcement因为它是解决此问题的最可靠和最新的站点。


根据不同的来源,我们似乎在使用 Spring Core 库时遇到了严重的安全问题。

引用上面的链接,如果出现以下情况,我们将面临风险:

  • 您使用 Spring 应用(5.3.17 及更高版本) 您的应用在 Java 9+ 上运行
  • 您使用名称=值对的表单绑定(bind)——而不是使用 Spring 更流行的 JSON/XML 消息转换
  • 您没有使用许可名单 – 或者 – 您没有阻止“类”、“模块”、“类加载器”等字段的拒绝名单

建议的某些解决方案的链接但似乎不容易实现/可靠。 我们应该如何以最简单和最可靠的方式解决此问题?

最佳答案

根据Spring Framework RCE: Early Announcement ,升级到 Spring Framework 5.3.18 或 5.2.20 将修复 RCE。

如果你使用 Spring Boot,Spring Boot 2.5.12Spring Boot 2.6.6修复漏洞。

如果您无法更新:

您可以选择只升级Tomcat。 The Apache Tomcat team has released versions 10.0.20, 9.0.62, and 8.5.78 all of which close the attack vector on Tomcat’s side .

如果您不能执行上述任何操作,RCE announcement blog帖子提出了一种解决方法:通过 @ControllerAdviceWebDataBinder 上设置 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);
    }

}

如果 Controller 通过其自己的 @InitBinder 方法在本地设置 disallowedFields,此快速修复将不起作用,该方法会覆盖全局设置。此外,更一般地说,如果您使用 Jersey 等替代 REST 框架,则该解决方法不会产生影响(但是,尚未证明此类配置会受到影响)。

关于spring - Spring RCE漏洞(CVE-2022-22965)如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71694298/

相关文章:

java - Spring - AutoWired 对象 NullPointerExpection、序列生成器

java - Spring-Boot REST 服务基本 http auth 排除一个端点

spring-boot - findAll() 上的 @NamedEntityGraphs

java - 如何在 Spring Boot 中跟踪唯一的 Web 请求?

java - 如何在 Spring Controller 的 Url 中传递多个变量?

java - 如何在 Spring-mvc 中使用 html 链接调用 Controller ?

java - 在 Spring Security 中添加组

java - Spring @ExceptionHandler 不处理错误

java - 为什么 JpaRepository.findAll() 方法从我的 Oracle 数据库中获取错误的数据?

spring - <portlet-preferences> 是否有 PropertyPlaceholderConfigurer?