SCW Icons
hero bg no divider
Blog

仔细研究 MVCrequestMatcher Spring 漏洞

Brysen Ackx
Published Apr 19, 2023
Last updated on Mar 09, 2026

On March 20th 2023, Spring Security Advisories published a blog post referencing an internally discovered vulnerability, CVE-2023-20860. No detailed information was disclosed, except that it was an access control issue concerning the use of mvcMatchers. Spring developers have remediated the issue, and a version update is advised.

Would you like a first hand experience? Try out the mission here.

As security is our main focus at Secure Code Warrior, we decided to take a deeper dive into this mvcRequestMatchers vulnerability and figure out where the core issue lies.

Spring provides the RequestMatcher interface to determine if a request matches a path pattern. Have a look at the code snippet below where the mvcMatchers helper method is used to register the endpoints along with their authentication and authorization requirements. For example, we can see that only users in the ADMIN role can access the /logs/audit endpoint. 

MvcMisMatchers?

In Spring, ** is a pattern to match any number of directories and subdirectories in a URL. For example,  /bankaccount/** would match all URLs starting with /bankaccount/, including subdirectories such as /bankaccount/dashboard/settings

The * pattern is a pattern that matches any URL and has exactly one level of a subdirectory. For example, /bankaccount/* would match bankaccount/dashboard.

When configuring the matchers with *, Spring states that "a mismatch in pattern matching between Spring Security and Spr ing MVC" took place, creating the vulnerability.

Essentially, due to the lack of a separator in front of the double wildcard, the path doesn’t match an incoming request as all incoming requests are prepended by a slash. This means that the access control rules aren’t applied and allowing any unauthenticated user to access the resources.

Let’s have a look at the commit that fixed the issue.

The most prominent and important change is the addition of line 315, which fixes the bypassing of the authorization and authentication rules. It ensures that any path pattern that is submitted, is prepended with a forward slash (/). 

404 match not found

PathPatternMatchableHandlerMapping class (Source spring-framework)

When sending a web request to /bankaccounts/view the match method will parse and compare the patterns defined in the security filter with the requested path. The parser will turn the given pattern into a tree of path elements.

The parser reads the first character as a SeparatorPathElement. It then continues reading the string characters until the next separator, creating a new LiteralPathElement. 

So where does it go wrong when using ** as the pattern? 

While there are plenty of path element types, the most interesting ones here are the WildcardPathElement and the WildcardTheRestPathElement, with their respective string representations: * and /**. 

A WildcardPathElement matches zero or more characters within a single path segment, while a WildcardTheRestPathElement matches zero or more path segments on their own (including the separators).

The latter one gives us a clue to what goes wrong when submitting ** as a pattern. During parsing it looks for patterns, but ** doesn’t start with the expected forward slash. So instead of becoming a WildcardTheRestPathElement, it becomes two consecutive WildcardPathElements.

Next, the parsed pattern is used to match against the requested URL. Paths are expected to start with a forward slash, but a wildcard does not match on separators.

Excerpt from WildCardPathElement.java

This means that instead of a RequestMatchResult, a null is returned. Consequently, the access control rules placed on this matcher won’t be applied on the requested URL.

Spring fixed the issue by prepending a slash. In other words, any ** pattern becomes /**, meaning it can be parsed as a WildcardTheRestPathElement, and a RequestMatchResult will be returned as the pattern is now matching the requested URL.

Vulnerability or API misuse?

It’s debatable whether this should be considered a vulnerability, as the code works as intended. The issue basically lies in the fact that the Spring documentation lacks an explicit mention that paths should start with a separator. Therefore, it could be considered more of a case of API misuse, instead of a bug or vulnerability.

黄色几何抽象背景上的骷髅图标
黄色几何抽象背景上的骷髅图标
查看资源
查看资源

2023 年 3 月 20 日,Spring Security Advisories 发布了一篇博客文章,引用了内部发现的漏洞 CVE-2023-20860。没有透露任何详细信息,只是这是与使用 “mvcMatchers” 有关的访问控制问题。Spring 开发人员已经修复了这个问题,建议进行版本更新。由于安全是我们在Secure Code Warrior的主要关注点,因此我们决定更深入地研究这个MvcRequestMatchers漏洞,找出核心问题所在。

对更多感兴趣?

learn more

Secure Code Warrior可以帮助您的组织在整个软件开发生命周期中保护代码,并营造一种将网络安全放在首位的文化。无论您是 AppSec 经理、开发人员、首席信息安全官还是任何与安全相关的人,我们都可以帮助您的组织降低与不安全代码相关的风险。

预订演示
分享到:
linkedin brandsSocialx logo
作者
Brysen Ackx
Published Apr 19, 2023

Brysen is a software developer at Secure Code Warrior with a focus on writing secure code.

分享到:
linkedin brandsSocialx logo
黄色几何抽象背景上的骷髅图标
黄色几何抽象背景上的骷髅图标

On March 20th 2023, Spring Security Advisories published a blog post referencing an internally discovered vulnerability, CVE-2023-20860. No detailed information was disclosed, except that it was an access control issue concerning the use of mvcMatchers. Spring developers have remediated the issue, and a version update is advised.

Would you like a first hand experience? Try out the mission here.

As security is our main focus at Secure Code Warrior, we decided to take a deeper dive into this mvcRequestMatchers vulnerability and figure out where the core issue lies.

Spring provides the RequestMatcher interface to determine if a request matches a path pattern. Have a look at the code snippet below where the mvcMatchers helper method is used to register the endpoints along with their authentication and authorization requirements. For example, we can see that only users in the ADMIN role can access the /logs/audit endpoint. 

MvcMisMatchers?

In Spring, ** is a pattern to match any number of directories and subdirectories in a URL. For example,  /bankaccount/** would match all URLs starting with /bankaccount/, including subdirectories such as /bankaccount/dashboard/settings

The * pattern is a pattern that matches any URL and has exactly one level of a subdirectory. For example, /bankaccount/* would match bankaccount/dashboard.

When configuring the matchers with *, Spring states that "a mismatch in pattern matching between Spring Security and Spr ing MVC" took place, creating the vulnerability.

Essentially, due to the lack of a separator in front of the double wildcard, the path doesn’t match an incoming request as all incoming requests are prepended by a slash. This means that the access control rules aren’t applied and allowing any unauthenticated user to access the resources.

Let’s have a look at the commit that fixed the issue.

The most prominent and important change is the addition of line 315, which fixes the bypassing of the authorization and authentication rules. It ensures that any path pattern that is submitted, is prepended with a forward slash (/). 

404 match not found

PathPatternMatchableHandlerMapping class (Source spring-framework)

When sending a web request to /bankaccounts/view the match method will parse and compare the patterns defined in the security filter with the requested path. The parser will turn the given pattern into a tree of path elements.

The parser reads the first character as a SeparatorPathElement. It then continues reading the string characters until the next separator, creating a new LiteralPathElement. 

So where does it go wrong when using ** as the pattern? 

While there are plenty of path element types, the most interesting ones here are the WildcardPathElement and the WildcardTheRestPathElement, with their respective string representations: * and /**. 

A WildcardPathElement matches zero or more characters within a single path segment, while a WildcardTheRestPathElement matches zero or more path segments on their own (including the separators).

The latter one gives us a clue to what goes wrong when submitting ** as a pattern. During parsing it looks for patterns, but ** doesn’t start with the expected forward slash. So instead of becoming a WildcardTheRestPathElement, it becomes two consecutive WildcardPathElements.

Next, the parsed pattern is used to match against the requested URL. Paths are expected to start with a forward slash, but a wildcard does not match on separators.

Excerpt from WildCardPathElement.java

This means that instead of a RequestMatchResult, a null is returned. Consequently, the access control rules placed on this matcher won’t be applied on the requested URL.

Spring fixed the issue by prepending a slash. In other words, any ** pattern becomes /**, meaning it can be parsed as a WildcardTheRestPathElement, and a RequestMatchResult will be returned as the pattern is now matching the requested URL.

Vulnerability or API misuse?

It’s debatable whether this should be considered a vulnerability, as the code works as intended. The issue basically lies in the fact that the Spring documentation lacks an explicit mention that paths should start with a separator. Therefore, it could be considered more of a case of API misuse, instead of a bug or vulnerability.

查看资源
查看资源

填写下面的表格下载报告

我们希望获得您的许可,以便向您发送有关我们的产品和/或相关安全编码主题的信息。我们将始终非常谨慎地对待您的个人信息,绝不会出于营销目的将其出售给其他公司。

提交
scw success icon
scw error icon
要提交表单,请启用 “分析” Cookie。完成后,可以随意再次禁用它们。
黄色几何抽象背景上的骷髅图标

On March 20th 2023, Spring Security Advisories published a blog post referencing an internally discovered vulnerability, CVE-2023-20860. No detailed information was disclosed, except that it was an access control issue concerning the use of mvcMatchers. Spring developers have remediated the issue, and a version update is advised.

Would you like a first hand experience? Try out the mission here.

As security is our main focus at Secure Code Warrior, we decided to take a deeper dive into this mvcRequestMatchers vulnerability and figure out where the core issue lies.

Spring provides the RequestMatcher interface to determine if a request matches a path pattern. Have a look at the code snippet below where the mvcMatchers helper method is used to register the endpoints along with their authentication and authorization requirements. For example, we can see that only users in the ADMIN role can access the /logs/audit endpoint. 

MvcMisMatchers?

In Spring, ** is a pattern to match any number of directories and subdirectories in a URL. For example,  /bankaccount/** would match all URLs starting with /bankaccount/, including subdirectories such as /bankaccount/dashboard/settings

The * pattern is a pattern that matches any URL and has exactly one level of a subdirectory. For example, /bankaccount/* would match bankaccount/dashboard.

When configuring the matchers with *, Spring states that "a mismatch in pattern matching between Spring Security and Spr ing MVC" took place, creating the vulnerability.

Essentially, due to the lack of a separator in front of the double wildcard, the path doesn’t match an incoming request as all incoming requests are prepended by a slash. This means that the access control rules aren’t applied and allowing any unauthenticated user to access the resources.

Let’s have a look at the commit that fixed the issue.

The most prominent and important change is the addition of line 315, which fixes the bypassing of the authorization and authentication rules. It ensures that any path pattern that is submitted, is prepended with a forward slash (/). 

404 match not found

PathPatternMatchableHandlerMapping class (Source spring-framework)

When sending a web request to /bankaccounts/view the match method will parse and compare the patterns defined in the security filter with the requested path. The parser will turn the given pattern into a tree of path elements.

The parser reads the first character as a SeparatorPathElement. It then continues reading the string characters until the next separator, creating a new LiteralPathElement. 

So where does it go wrong when using ** as the pattern? 

While there are plenty of path element types, the most interesting ones here are the WildcardPathElement and the WildcardTheRestPathElement, with their respective string representations: * and /**. 

A WildcardPathElement matches zero or more characters within a single path segment, while a WildcardTheRestPathElement matches zero or more path segments on their own (including the separators).

The latter one gives us a clue to what goes wrong when submitting ** as a pattern. During parsing it looks for patterns, but ** doesn’t start with the expected forward slash. So instead of becoming a WildcardTheRestPathElement, it becomes two consecutive WildcardPathElements.

Next, the parsed pattern is used to match against the requested URL. Paths are expected to start with a forward slash, but a wildcard does not match on separators.

Excerpt from WildCardPathElement.java

This means that instead of a RequestMatchResult, a null is returned. Consequently, the access control rules placed on this matcher won’t be applied on the requested URL.

Spring fixed the issue by prepending a slash. In other words, any ** pattern becomes /**, meaning it can be parsed as a WildcardTheRestPathElement, and a RequestMatchResult will be returned as the pattern is now matching the requested URL.

Vulnerability or API misuse?

It’s debatable whether this should be considered a vulnerability, as the code works as intended. The issue basically lies in the fact that the Spring documentation lacks an explicit mention that paths should start with a separator. Therefore, it could be considered more of a case of API misuse, instead of a bug or vulnerability.

观看网络研讨会
开始吧
learn more

点击下面的链接并下载此资源的PDF。

Secure Code Warrior可以帮助您的组织在整个软件开发生命周期中保护代码,并营造一种将网络安全放在首位的文化。无论您是 AppSec 经理、开发人员、首席信息安全官还是任何与安全相关的人,我们都可以帮助您的组织降低与不安全代码相关的风险。

查看报告预订演示
查看资源
分享到:
linkedin brandsSocialx logo
对更多感兴趣?

试试我们的使命,亲身体验影响,学习如何避免犯类似的错误。

现在就试试吧
分享到:
linkedin brandsSocialx logo
作者
Brysen Ackx
Published Apr 19, 2023

Brysen is a software developer at Secure Code Warrior with a focus on writing secure code.

分享到:
linkedin brandsSocialx logo

On March 20th 2023, Spring Security Advisories published a blog post referencing an internally discovered vulnerability, CVE-2023-20860. No detailed information was disclosed, except that it was an access control issue concerning the use of mvcMatchers. Spring developers have remediated the issue, and a version update is advised.

Would you like a first hand experience? Try out the mission here.

As security is our main focus at Secure Code Warrior, we decided to take a deeper dive into this mvcRequestMatchers vulnerability and figure out where the core issue lies.

Spring provides the RequestMatcher interface to determine if a request matches a path pattern. Have a look at the code snippet below where the mvcMatchers helper method is used to register the endpoints along with their authentication and authorization requirements. For example, we can see that only users in the ADMIN role can access the /logs/audit endpoint. 

MvcMisMatchers?

In Spring, ** is a pattern to match any number of directories and subdirectories in a URL. For example,  /bankaccount/** would match all URLs starting with /bankaccount/, including subdirectories such as /bankaccount/dashboard/settings

The * pattern is a pattern that matches any URL and has exactly one level of a subdirectory. For example, /bankaccount/* would match bankaccount/dashboard.

When configuring the matchers with *, Spring states that "a mismatch in pattern matching between Spring Security and Spr ing MVC" took place, creating the vulnerability.

Essentially, due to the lack of a separator in front of the double wildcard, the path doesn’t match an incoming request as all incoming requests are prepended by a slash. This means that the access control rules aren’t applied and allowing any unauthenticated user to access the resources.

Let’s have a look at the commit that fixed the issue.

The most prominent and important change is the addition of line 315, which fixes the bypassing of the authorization and authentication rules. It ensures that any path pattern that is submitted, is prepended with a forward slash (/). 

404 match not found

PathPatternMatchableHandlerMapping class (Source spring-framework)

When sending a web request to /bankaccounts/view the match method will parse and compare the patterns defined in the security filter with the requested path. The parser will turn the given pattern into a tree of path elements.

The parser reads the first character as a SeparatorPathElement. It then continues reading the string characters until the next separator, creating a new LiteralPathElement. 

So where does it go wrong when using ** as the pattern? 

While there are plenty of path element types, the most interesting ones here are the WildcardPathElement and the WildcardTheRestPathElement, with their respective string representations: * and /**. 

A WildcardPathElement matches zero or more characters within a single path segment, while a WildcardTheRestPathElement matches zero or more path segments on their own (including the separators).

The latter one gives us a clue to what goes wrong when submitting ** as a pattern. During parsing it looks for patterns, but ** doesn’t start with the expected forward slash. So instead of becoming a WildcardTheRestPathElement, it becomes two consecutive WildcardPathElements.

Next, the parsed pattern is used to match against the requested URL. Paths are expected to start with a forward slash, but a wildcard does not match on separators.

Excerpt from WildCardPathElement.java

This means that instead of a RequestMatchResult, a null is returned. Consequently, the access control rules placed on this matcher won’t be applied on the requested URL.

Spring fixed the issue by prepending a slash. In other words, any ** pattern becomes /**, meaning it can be parsed as a WildcardTheRestPathElement, and a RequestMatchResult will be returned as the pattern is now matching the requested URL.

Vulnerability or API misuse?

It’s debatable whether this should be considered a vulnerability, as the code works as intended. The issue basically lies in the fact that the Spring documentation lacks an explicit mention that paths should start with a separator. Therefore, it could be considered more of a case of API misuse, instead of a bug or vulnerability.

目录

下载PDF
查看资源
对更多感兴趣?

learn more

Secure Code Warrior可以帮助您的组织在整个软件开发生命周期中保护代码,并营造一种将网络安全放在首位的文化。无论您是 AppSec 经理、开发人员、首席信息安全官还是任何与安全相关的人,我们都可以帮助您的组织降低与不安全代码相关的风险。

预订演示下载
分享到:
linkedin brandsSocialx logo
资源中心

帮助您入门的资源

更多帖子
资源中心

帮助您入门的资源

更多帖子