GHSA-36p3-wjmg-h94x CVE-2022-22965
Remote Code Execution in Spring Framework
- Severity
- 9.8 / 10
- Critical · CVSS 3.1
- Exploit chance (EPSS)
- 99.64%
- Chance of exploitation in the next 30 days. Higher than 99.95% of scored vulnerabilities.
- Known exploited
- Yes
- In CISA's catalog since Apr 4, 2022
- Weakness
- CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Fix
- Available
- 5 packages have a fixed version
Description
Spring Framework prior to versions 5.2.20 and 5.3.18 contains a remote code execution vulnerability known as Spring4Shell.
Impact
A Spring MVC or Spring WebFlux application running on JDK 9+ may be vulnerable to remote code execution (RCE) via data binding. The specific exploit requires the application to run on Tomcat as a WAR deployment. If the application is deployed as a Spring Boot executable jar, i.e. the default, it is not vulnerable to the exploit. However, the nature of the vulnerability is more general, and there may be other ways to exploit it.
These are the prerequisites for the exploit:
- JDK 9 or higher
- Apache Tomcat as the Servlet container
- Packaged as WAR
spring-webmvcorspring-webfluxdependency
Patches
Workarounds
For those who are unable to upgrade, leaked reports recommend setting disallowedFields on WebDataBinder through an @ControllerAdvice. This works generally, but as a centrally applied workaround fix, may leave some loopholes, in particular if a controller sets disallowedFields locally through its own @InitBinder method, which overrides the global setting.
To apply the workaround in a more fail-safe way, applications could extend RequestMappingHandlerAdapter to update the WebDataBinder at the end after all other initialization. In order to do that, a Spring Boot application can declare a WebMvcRegistrations bean (Spring MVC) or a WebFluxRegistrations bean (Spring WebFlux).
Affected versions
Maven
How to fix
Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.
org.springframework.boot:spring-boot-starter-web Maven → 2.5.12
- maven
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.5.12</version></dependency>- gradle
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12")
org.springframework.boot:spring-boot-starter-webflux Maven → 2.5.12
- maven
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId><version>2.5.12</version></dependency>- gradle
implementation("org.springframework.boot:spring-boot-starter-webflux:2.5.12")
org.springframework:spring-beans Maven → 5.3.18
- maven
<dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>5.3.18</version></dependency>- gradle
implementation("org.springframework:spring-beans:5.3.18")
org.springframework:spring-webflux Maven → 5.3.18
- maven
<dependency><groupId>org.springframework</groupId><artifactId>spring-webflux</artifactId><version>5.3.18</version></dependency>- gradle
implementation("org.springframework:spring-webflux:5.3.18")
org.springframework:spring-webmvc Maven → 5.3.18
- maven
<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.18</version></dependency>- gradle
implementation("org.springframework:spring-webmvc:5.3.18")
Severity breakdown
CVSS 3.1 9.8
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:H
- Attack vector
- Network
- Attack complexity
- Low
- Privileges required
- None
- User interaction
- None
- Scope
- Unchanged
- Confidentiality
- High
- Integrity
- High
- Availability
- High
- Exploit maturity
- H
Weakness
CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
How to prevent it
- Requirements: Programming languages and supporting technologies might be chosen which are not subject to these issues.
- Implementation: Utilize an appropriate mix of allowlist and denylist parsing to filter control-plane syntax from all input.
CWE-94: Improper Control of Generation of Code ('Code Injection')
The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
How to prevent it
- Architecture and Design: Refactor your program so that you do not have to dynamically generate code.
- Architecture and Design: Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which code can be executed by your product. Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.
- Implementation: Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. To reduce the likelihood of code injection, use stringent allowlists that limit which constructs are allowed. If you are dynamically constructing code that invokes a function, then verifying that the input is alphanumeric might be insufficient. An attacker might still be able to reference a dangerous function that you did not intend to allow, such as system(), exec(), or exit().
- Testing: Use dynamic tools and techniques that interact with the product using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The product's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
- Operation: Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
- Operation: Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
- Implementation: For Python programs, it is frequently encouraged to use the ast.literal_eval() function instead of eval, since it is intentionally designed to avoid executing code. However, an adversary could still cause excessive memory or stack consumption via deeply nested structures [REF-1372], so the python documentation discourages use of ast.literal_eval() on untrusted data [REF-1373].
References
Advisories
Fixes and patches
Packages
Other links
- github.com/spring-projects/spring-boot/releases/tag/v2.5.12
- github.com/spring-projects/spring-boot/releases/tag/v2.6.6
- github.com/spring-projects/spring-framework/releases/tag/v5.2.20.RELEASE
- github.com/spring-projects/spring-framework/releases/tag/v5.3.18
- spring.io/blog/2022/03/31/spring-framework-rce-early-announcement
- tanzu.vmware.com/security/cve-2022-22965
- cert-portal.siemens.com/productcert/pdf/ssa-254054.pdf
- psirt.global.sonicwall.com/vuln-detail/SNWLID-2022-0005
- tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-java-spring-r…
- oracle.com/security-alerts/cpuapr2022.html
- packetstormsecurity.com/files/166713/Spring4Shell-Code-Execution.html
- packetstormsecurity.com/files/167011/Spring4Shell-Spring-Framework-Class-Property-Remote-Cod…
- oracle.com/security-alerts/cpujul2022.html
- kb.cert.org/vuls/id/970766
- cisa.gov/known-exploited-vulnerabilities-catalog
Timeline
- Published
- Added to CISA's Known Exploited Vulnerabilities catalog
- Remediation due for U.S. federal agencies
- Last updated by the source
- Latest EPSS score
Related advisories
| Advisory | Severity | Why it's related |
|---|---|---|
| GHSA-9qf2-26p9-2q2q Spring Framework Header Predicate Bypass in WebFlux Functional Endpoints | Critical | Also affects org.springframework:spring-webflux |
| GHSA-j9f9-w8pj-32f8 Spring Framework Server Sent Event stream corruption while rendering fragments | Critical | Also affects org.springframework:spring-webflux |
| GHSA-pc63-qcmh-9cmg Spring Framework Improper Path Limitation in XsltView | Critical | Also affects org.springframework:spring-webmvc |
| GHSA-cjpg-rgq5-fr37 Spring Framework Multipart Request Smuggling in Spring MVC and WebFlux | Medium | Also affects org.springframework:spring-webflux |
| GHSA-vqgp-pf68-6947 Spring Framework Security Filter Bypass in WebFlux Kotlin Router DSL | Medium | Also affects org.springframework:spring-webflux |
| GHSA-957g-f97v-vppc Spring Framework Cross-site Scripting via JSP Form Tags | Medium | Also affects org.springframework:spring-webmvc |
| GHSA-3chg-m5w7-qfv5 Spring Framework Cross-site Scripting via JavaScriptUtils | Medium | Also affects org.springframework:spring-webmvc |
| GHSA-h3qp-gqrc-q736 Spring Framework Open Redirect in Spring MVC and WebFlux | Medium | Also affects org.springframework:spring-webflux |
Credits: briandealwis, cdupuis, rotilho
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor