# CVE-2021-22112: Privilege escalation in spring security

> Spring Security fails to save SecurityContext changes, allowing attackers to extend elevated privileges across the application if specific coding patterns are present.

- **Severity:** High 8.8 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 23 Feb 2021
- **Updated:** 3 Aug 2024
- **Also known as:** GHSA-gq28-h5vg-8prx, ROOT-APP-MAVEN-CVE-2021-22112

## What is CVE-2021-22112?

CVE-2021-22112 is a high-severity vulnerability in Oracle Communications Element Manager, published on 23 Feb 2021. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Spring Security 5.4.x prior to 5.4.4, 5.3.x prior to 5.3.8.RELEASE, 5.2.x prior to 5.2.9.RELEASE, and older unsupported versions can fail to save the SecurityContext if it is changed more than once in a single request.A malicious user cannot cause the bug to happen (it must be programmed in). However, if the application's intent is to only allow the user to run with elevated privileges in a small portion of the application, the bug can be leveraged to extend those privileges to the rest of the application.

## Which versions are affected by CVE-2021-22112?

12 open source packages ship an affected version, including org.springframework.security:spring-security-bom and org.springframework.security:spring-security-web. It affects 8 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `org.springframework.security:spring-security-bom` | Maven | All versions | 5.2.9 |
| `org.springframework.security:spring-security-bom` | Maven | All versions | 5.2.9 |
| `org.springframework.security:spring-security-bom` | Maven | From 5.3.0 | 5.3.8 |
| `org.springframework.security:spring-security-bom` | Maven | From 5.3.0 | 5.3.8 |
| `org.springframework.security:spring-security-bom` | Maven | From 5.4.0 | 5.4.4 |
| `org.springframework.security:spring-security-bom` | Maven | From 5.4.0 | 5.4.4 |
| `org.springframework.security:spring-security-web` | Maven | All versions | 5.2.9 |
| `org.springframework.security:spring-security-web` | Maven | All versions | 5.2.9 |
| `org.springframework.security:spring-security-web` | Maven | From 5.3.0 | 5.3.8 |
| `org.springframework.security:spring-security-web` | Maven | From 5.3.0 | 5.3.8 |
| `org.springframework.security:spring-security-web` | Maven | From 5.4.0 | 5.4.4 |
| `org.springframework.security:spring-security-web` | Maven | From 5.4.0 | 5.4.4 |

Products: Oracle Communications Element Manager, Oracle Communications Interactive Session Recorder, Oracle Communications Unified Inventory Management, Oracle Hospitality Cruise Shipboard Property Management System, Oracle Insurance Policy Administration, Oracle Mysql Enterprise Monitor, Pivotal Software Spring Security, Vmware Spring Security.

## How do I fix CVE-2021-22112?

Upgrade org.springframework.security:spring-security-bom to a fixed version for your release line: 5.2.9, 5.3.8 or 5.4.4.

## Is CVE-2021-22112 being exploited?

There is no known exploitation of CVE-2021-22112 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-22112 and fix it if it is affected.

What it is: CVE-2021-22112 is a high-severity vulnerability in Oracle Communications Element Manager, published on 23 Feb 2021. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-22112 in the wild and no public exploit code.

Affected packages and fixed versions:
- org.springframework.security:spring-security-bom (Maven): affected all versions; fixed in 5.2.9
- org.springframework.security:spring-security-bom (Maven): affected all versions; fixed in 5.2.9
- org.springframework.security:spring-security-bom (Maven): affected from 5.3.0; fixed in 5.3.8
- org.springframework.security:spring-security-bom (Maven): affected from 5.3.0; fixed in 5.3.8
- org.springframework.security:spring-security-bom (Maven): affected from 5.4.0; fixed in 5.4.4
- org.springframework.security:spring-security-bom (Maven): affected from 5.4.0; fixed in 5.4.4
- org.springframework.security:spring-security-web (Maven): affected all versions; fixed in 5.2.9
- org.springframework.security:spring-security-web (Maven): affected all versions; fixed in 5.2.9
- org.springframework.security:spring-security-web (Maven): affected from 5.3.0; fixed in 5.3.8
- org.springframework.security:spring-security-web (Maven): affected from 5.3.0; fixed in 5.3.8
- org.springframework.security:spring-security-web (Maven): affected from 5.4.0; fixed in 5.4.4
- org.springframework.security:spring-security-web (Maven): affected from 5.4.0; fixed in 5.4.4

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2021-22112/ (Markdown: https://insights.sbomify.com/CVE-2021-22112/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-22112
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-22112
- OSV: https://osv.dev/vulnerability/CVE-2021-22112

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-22112/
Summaries are generated and may contain mistakes; the official description above is the record.
