CVE-2021-22112 Overview
CVE-2021-22112 is a privilege escalation vulnerability affecting Spring Security versions 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. The vulnerability occurs when the SecurityContext is changed more than once in a single request, potentially failing to save the updated context properly. While a malicious user cannot directly trigger this bug (it must be introduced through application code), if an application intends to grant elevated privileges only for a limited portion of its functionality, an attacker could leverage this flaw to extend those privileges across the entire application.
Critical Impact
Authenticated users could potentially extend elevated privileges beyond their intended scope, gaining unauthorized access to restricted application functionality and sensitive resources.
Affected Products
- Pivotal Software Spring Security (versions prior to 5.4.4, 5.3.8.RELEASE, 5.2.9.RELEASE)
- VMware Spring Security
- Oracle Communications Element Manager
- Oracle Communications Interactive Session Recorder (versions 6.3, 6.4)
- Oracle Communications Unified Inventory Management (version 7.4.1)
- Oracle Hospitality Cruise Shipboard Property Management System (version 20.1.0)
- Oracle Insurance Policy Administration (versions 11.2.0, 11.3.0)
- Oracle MySQL Enterprise Monitor
Discovery Timeline
- February 23, 2021 - CVE-2021-22112 published to NVD
- November 21, 2024 - Last updated in NVD database
Technical Details for CVE-2021-22112
Vulnerability Analysis
This vulnerability affects the SecurityContext handling mechanism in Spring Security, which is responsible for maintaining authentication and authorization state throughout the lifecycle of HTTP requests. When an application modifies the SecurityContext multiple times within a single request—such as temporarily elevating a user's privileges for a specific operation—the framework may fail to persist the final state correctly.
The core issue lies in how Spring Security manages the SecurityContextHolder during request processing. Applications that implement step-up authentication patterns or temporary privilege elevation are particularly susceptible. In these scenarios, developers might programmatically grant additional authorities to a user for a specific code path, expecting the original context to be restored afterward. However, due to this bug, the elevated privileges may persist beyond their intended scope.
Root Cause
The root cause stems from a race condition in the SecurityContext persistence mechanism. When the SecurityContext is modified multiple times within a single request, the framework's context persistence logic may not correctly track all changes, causing subsequent saves to be skipped or improperly handled. This results in an inconsistent security state where elevated privileges granted temporarily are not properly revoked at the expected boundaries.
Attack Vector
The vulnerability requires the following conditions for exploitation:
- Application Design Flaw: The target application must be coded in a way that modifies the SecurityContext multiple times during a single request
- Authenticated Access: The attacker must have valid authentication credentials to access the application
- Privilege Boundary: The application must implement functionality that grants temporary elevated privileges to users
An attacker with low-level access to such an application could identify endpoints or workflows where temporary privilege elevation occurs and then leverage the bug to retain those elevated privileges for subsequent operations. This could allow access to administrative functions, sensitive data retrieval, or modification of protected resources.
The attack scenario involves an authenticated user triggering the vulnerable code path where privilege elevation occurs, then leveraging the unsaved context state to access functionality that should require the elevated privileges they were only temporarily granted.
Detection Methods for CVE-2021-22112
Indicators of Compromise
- Unusual access patterns where low-privilege users access administrative or restricted endpoints
- Authentication logs showing users successfully accessing resources beyond their normal authorization level
- Application logs indicating SecurityContext changes that don't align with expected user privilege flows
- Audit trail anomalies showing privilege escalation without corresponding step-up authentication events
Detection Strategies
- Review application code for patterns where SecurityContextHolder.setContext() or SecurityContext.setAuthentication() is called multiple times within request handlers
- Monitor access control logs for users accessing resources outside their designated privilege scope
- Implement runtime security monitoring to detect authentication state inconsistencies during request processing
- Deploy application security testing tools to identify vulnerable code patterns in Spring Security implementations
Monitoring Recommendations
- Enable detailed Spring Security debug logging to track SecurityContext lifecycle events
- Configure audit logging for all privilege elevation operations and their expected duration
- Implement alerting for access control violations where users reach restricted endpoints
- Monitor for abnormal session behavior patterns that may indicate privilege persistence issues
How to Mitigate CVE-2021-22112
Immediate Actions Required
- Upgrade Spring Security to patched versions: 5.4.4 or later, 5.3.8.RELEASE or later, or 5.2.9.RELEASE or later
- Review application code to identify any patterns that modify SecurityContext multiple times per request
- Implement additional authorization checks at sensitive endpoints as a defense-in-depth measure
- Audit access logs for any evidence of privilege escalation exploitation
Patch Information
VMware has released security patches to address this vulnerability. Organizations should update to the following versions:
- Spring Security 5.4.x: Upgrade to 5.4.4 or later
- Spring Security 5.3.x: Upgrade to 5.3.8.RELEASE or later
- Spring Security 5.2.x: Upgrade to 5.2.9.RELEASE or later
For detailed patch information, refer to the VMware Tanzu CVE-2021-22112 Advisory. Oracle users should consult the Oracle CPU April 2021 Alerts and Oracle CPU October 2021 Alerts for updates to affected Oracle products.
Workarounds
- Refactor application code to avoid multiple SecurityContext modifications within a single request
- Implement explicit SecurityContext save operations after each modification if upgrading is not immediately possible
- Use SecurityContextPersistenceFilter with explicit save behavior configuration
- Add redundant authorization checks at each privilege boundary to verify expected access levels
# Verify Spring Security version in Maven project
mvn dependency:tree | grep spring-security
# Update Spring Security in pom.xml to patched version
# For Spring Security 5.4.x:
# <spring-security.version>5.4.4</spring-security.version>
# Rebuild and redeploy application
mvn clean package
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


