重要 | SpringBoot 最新版本无法启动问题说明

JAVA架构日记

共 2140字,需浏览 5分钟

 · 2023-07-29

启动报错

问题描述:在升级SpringBoot 版本来修复 CVE-2023-34034 and CVE-2023-34035 漏洞时, 启动后报错如下应用无法正常运行

This method cannot decide whether these patterns are Spring MVC patterns or not.
If this endpoint is a Spring MVC endpoint, please use `requestMatchers(MvcRequestMatcher)`;
otherwise, please use `requestMatchers(AntPathRequestMatcher)`.

问题原因

Spring Security 版本 5.8 在 5.8.5 之前,6.0 在 6.0.5 之前,6.1 在 6.1.2 之前,如果应用程序使用 requestMatchers(String)和多个 servlet(其中一个是 Spring MVC 的 DispatcherServlet),则可能容易受到授权规则配置错误 CVE 安全漏洞影响。具体可参考 《CVE-2023-34035: Authorization rules can be misconfigured when using multiple servlets》[1]

(DispatcherServlet 是 Spring MVC 组件,将 HTTP 端点映射到@Controller 注释类上的方法。)具体来说,当满足以下所有条件时,应用程序就存在漏洞:

classpath 中存在 Spring MVC Spring Security 在单个应用程序中保护多个 servlet(其中一个是 Spring MVC 的 DispatcherServlet) 应用程序使用 requestMatchers(String)来引用非 Spring MVC 端点 如果满足以下任何条件,则应用程序不会受到影响:

应用程序的 classpath 中不存在 Spring MVC 应用程序只保护了 Spring MVC 的 DispatcherServlet 以外的 servlets 应用程序仅针对 Spring MVC 端点使用了 requestMatchers(String) 受影响的 Spring 产品和版本

  • Spring Security 5.8.0 至 5.8.4
  • Spring Security 6.0.0 至 6.0.4
  • Spring Security 6.1.0 至 6.1.1

缓解措施 受影响版本的用户应采取以下缓解措施。

首先:

5.8.x 用户应升级到 5.8.5 (SpringBoot 2.7.14) 6.0.x 用户应升级到 6.0.5 (SpringBoot 3.0.9) 6.1.x 用户应升级到 6.1.2 (SpringBoot 3.1.2)

其次,如果您使用多个 servlet,并且其中一个是 Spring MVC 的 DispatcherServlet,则可能在启动时看到以下错误消息:

This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use `requestMatchers(AntPathRequestMatcher)。

请按照此错误消息进行操作。

例如,如果您正在使用 requestMatchers(String)指向非 Spring MVC 端点/endpoint,则将其更改为 requestMatchers(new AntPathRequestMatcher("/endpoint"))。

参考资料

[1]

《CVE-2023-34035: Authorization rules can be misconfigured when using multiple servlets》: https://spring.io/security/cve-2023-34035


浏览 1431
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报