Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2022-22978 — Step-by-step demonstration of CVE-2022-22978 authorization bypass in Spring Security's RegexRequestMatcher, with vulnerable app setup, payload execution, and fix verification. | Kitploit
Tools/GitHubGitHub/umakant76705/cve-2022-22978
Authentication & AuthorizationVulnerability AnalysisWeb Application ExploitationPenetration TestingLearning & EducationLabs & Practice
GitHubumakant76705/cve-2022-22978

CVE-2022-22978

Step-by-step demonstration of CVE-2022-22978 authorization bypass in Spring Security's RegexRequestMatcher, with vulnerable app setup, payload execution, and fix verification.

View Repository
224 years agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

CVE 2022-22978: Authorization Bypass in RegexRequestMatcher 🥶

Overview

According to the information I have gathered, this vulnerability relates to the RegexRequestMatcher class in the Spring Security framework. Specifically, applications using RegexRequestMatcher where the regular expression contains a dot (.) can be bypassed using the characters \r(%0a) and \n(%0d); thus attackers can access disallowed paths without authentication.

Affected versions of the Spring Security framework:

  • 5.5.x before 5.5.7
  • 5.6.x before 5.6.4
  • Earlier unsupported versions.

Analysis

We need to access the Spring Security source code to perform a static analysis of this vulnerability. Specifically, I used the commit comparison feature between versions 5.6.3 (vulnerable version) and 5.6.4 (fixed version) on Github. See the following link: Comparing 5.6.3...5.6.4 · spring-projects/spring-security (github.com)

img1

I checked the changes in the RegexRequestMatcher class. It can be seen that in version 5.6.4, this class uses Pattern.DOTALL instead of the default . as in version 5.6.3.

Where:

  • Pattern: is one of three classes in the java.util.regex package, used for processing regular expressions.
  • Pattern.DOTALL: When using this flag, “.” in the regular expression will match all characters, including line terminators such as \n , \r.
  • Pattern.CASE_INSENSITIVE: ignores uppercase/lowercase characters.

img2

By default, the . in a regular expression matches all characters except line terminators like \n, \r. Therefore, if there is a regex function validating a pattern of some string, that regex will not match if the string contains line terminators. To avoid this, the Pattern.DOTALL flag can be used.

However, if someone intentionally uses %0d instead of \n or %0a instead of \r, the above regex still cannot match. Therefore, in version 5.6.4, an additional check for this case was added in RegexRequestMatcherTests.java. Specifically, it converts %0d and %0a to \n and \r respectively before checking with the regex.

img3

Demo

Step 1: Create a spring boot web application using Spring Initializr with two dependencies: Spring Security and Spring Web.

img4

Step 2: Create a Controller that prints the text This is a CVE-2022-22978 demo when a request is made to the path /admin/*

img5

Step 3: Set up an authentication mechanism for every time a user accesses the path /admin/<any> by using regexMatchers("/admin/.*").authenticated(). This is the vulnerability that attackers exploit to view the content of /admin/<any> pages without authentication.

img6

Step 4: In the configuration file, declare the version of Spring Security that contains the vulnerability. Here I choose version 5.6.3.

img7

Step 5: Run the application with the command gradlew bootRun. The program defaults to using Apache Tomcat listening on port 8080. Access the path /admin/xyz (any path starting with /admin/).

img8

The result returns a 403 Forbidden code, meaning access is denied due to lack of authentication.

Now, exploit the vulnerability of the regexMatchers function in Spring Security (version 5.6.3) which does not match line terminator characters like \r(%0d) and \n(%0a) → we can access the above path without authentication using the payload /admin/%0dxyz.

img9

Similarly with the payload /admin/%0axyz

img10

Thus, we have successfully exploited the CVE-2022-22978 vulnerability with a very simple payload.

Mitigation

  • Update the Spring Security version to:
    • 5.5.7+
    • 5.6.4+
    • 5.7+
  • Demo: Use the fixed version, specifically 5.7.1

img11

Try attacking the web with the same payload: /admin/%0dxyz

img12

At this point, the app no longer returns the response the attacker expected.

Usage

root@kitploit:~
git clone https://github.com/ducluongtran9121/CVE-2022-22978-PoC.git
cd CVE-2022-22978-PoC
gradlew bootRun

Requirements

root@kitploit:~
Java 18
Gradle 7.4.1
Download Tool