1. Home
  2. System Vulnerabilities
  3. How to remediate – Apache Struts 2.x < 2.5.22 Remote Code Execution (S2-059)

How to remediate – Apache Struts 2.x < 2.5.22 Remote Code Execution (S2-059)

1. Introduction

Apache Struts 2.x < 2.5.22 contains a Remote Code Execution (RCE) vulnerability, designated S2-059. This flaw allows attackers to execute arbitrary code on affected systems by exploiting forced double OGNL evaluation when processing user input in tag attributes. Successful exploitation could lead to complete system compromise. Confidentiality, integrity and availability may be impacted.

2. Technical Explanation

The vulnerability stems from Apache Struts 2.0.0 to 2.5.20 improperly handling OGNL evaluation on raw user input within tag attributes. An attacker can craft a malicious payload containing OGNL expressions that, when evaluated by the server, execute arbitrary code. The precondition for exploitation is an application using vulnerable versions of Apache Struts and accepting user-controlled data in tag attributes. CVE-2019-0230 details this issue.

  • Root cause: Forced double OGNL evaluation on raw user input within tag attributes.
  • Exploit mechanism: An attacker sends a crafted HTTP request containing malicious OGNL expressions embedded in tag attributes, leading to remote code execution. For example, an attacker could inject an expression that executes system commands.
  • Scope: Apache Struts 2.0.0 up to and including version 2.5.20 are affected.

3. Detection and Assessment

To confirm vulnerability, check the installed Struts version. A thorough assessment involves analyzing application code for usage of vulnerable tag attributes.

  • Quick checks: Check the struts.xml file or application dependencies to identify the Struts version in use.
  • Scanning: Static Application Security Testing (SAST) tools can detect vulnerable Struts versions and unsafe OGNL expressions. Examples include SonarQube with appropriate rulesets, or commercial SAST solutions.
  • Logs and evidence: Examine application logs for errors related to OGNL evaluation or suspicious activity involving tag attributes.
# Example command placeholder:
# No specific command exists to directly detect this vulnerability; check version via configuration files.

4. Solution / Remediation Steps

Apply the recommended fix from the vendor advisory. This typically involves upgrading Struts to a patched version.

4.1 Preparation

  • Ensure you have access to the application deployment environment and necessary permissions. A roll back plan is to restore from backup or redeploy the previous version of the application.
  • Coordinate with relevant stakeholders for change window approval, especially in production environments.

4.2 Implementation

  1. Step 1: Upgrade Apache Struts to version 2.5.22 or later. This can be done through your package manager (e.g., Maven, Gradle) or by replacing the existing Struts JAR files with patched versions.
  2. Step 2: Restart the application server for the changes to take effect.

4.3 Config or Code Example

Before

<s:textfield name="userInput" label="User Input"/>  

After

<s:textfield name="userInput" label="User Input" sanitizeHTML="true"/> 

4.4 Security Practices Relevant to This Vulnerability

Several security practices can mitigate the risk of RCE vulnerabilities like S2-059.

  • Least privilege: Run applications with the minimum necessary privileges to limit the impact of potential exploits.
  • Patch cadence: Regularly update all software components, including Apache Struts, to apply security patches promptly.

4.5 Automation (Optional)

Automated dependency scanning tools can help identify vulnerable Struts versions during build time.

# Example Maven command to check for vulnerabilities:
# mvn dependency-check:check

5. Verification / Validation

  • Post-fix check: Verify the Struts version in use is 2.5.22 or later by checking the struts.xml file or application dependencies. Expected output should show a version number greater than or equal to 2.5.22.
  • Re-test: Re-run the earlier detection methods (e.g., SAST scan) to confirm that the vulnerability is no longer detected.
  • Monitoring: Monitor application logs for any errors related to OGNL evaluation or suspicious activity involving tag attributes.
# Example command placeholder:
# No specific post-fix command exists; verify version via configuration files.

6. Preventive Measures and Monitoring

Implement security baselines, CI/CD pipeline checks, and a robust patch management process to prevent similar vulnerabilities in the future.

  • Baselines: Update your application security baseline to require the latest patched versions of Apache Struts.
  • Asset and patch process: Establish a regular patch review cycle (e.g., weekly or monthly) to identify and apply security updates promptly.

7. Risks, Side Effects, and Roll Back

Upgrading Apache Struts may introduce compatibility issues with existing application code. Have a roll back plan in place.

  • Risk or side effect 2: Potential downtime during application restart. Mitigation: Schedule the upgrade during a maintenance window with minimal user impact.
  • Roll back: Restore from backup or redeploy the previous version of the application and its configuration files.

8. References and Resources

Updated on October 26, 2025

Was this article helpful?

Related Articles