CVE-2021-42340: Apache Tomcat Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-wph7-x527-w3h5
CVSS 7.5
CWE-772
Published
Advisory Summary

CVE-2021-42340 is a HIGH (CVSS 7.5) remote code execution vulnerability (CWE-772: Missing Release of Resource after Effective Lifetime) affecting Apache Tomcat libraries in the Maven ecosystem. The issue involves missing release of resource after effective lifetime in apache tomcat. Remediation is available by upgrading affected packages to version 10.1.0-M6, 10.0.12, 9.0.54, 8.5.72.

CVE-2021-42340 at a Glance

CVE Identifier CVE-2021-42340
GHSA Identifier GHSA-wph7-x527-w3h5
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-772: Missing Release of Resource after Effective Lifetime
Affected Product Apache Tomcat
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2021-42340

To remediate this vulnerability, upgrade all affected Apache Tomcat dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

org.apache.tomcat:tomcat fixed: 10.1.0-M6
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat</artifactId>
    <version>10.1.0-M6</version>
</dependency>
org.apache.tomcat:tomcat fixed: 10.0.12
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat</artifactId>
    <version>10.0.12</version>
</dependency>
org.apache.tomcat:tomcat fixed: 9.0.54
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat</artifactId>
    <version>9.0.54</version>
</dependency>
org.apache.tomcat:tomcat fixed: 8.5.72
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat</artifactId>
    <version>8.5.72</version>
</dependency>
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

mvn dependency:tree -Dincludes=org.apache.tomcat

How to Check if You Are Affected

To determine whether your Java application is affected by CVE-2021-42340, inspect your build dependencies using the Maven Dependency Plugin:

mvn dependency:tree -Dincludes=org.apache.tomcat

Analyze the terminal output to locate any version of Apache Tomcat in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 10.1.0-M6), your application is affected.

Note: The mvn dependency:tree -Dincludes=org.apache.tomcat command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-772: Missing Release of Resource after Effective Lifetime, where the product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed. In Apache Tomcat, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

The fix for bug 63362 present in Apache Tomcat 10.1.0-M1 to 10.1.0-M5, 10.0.0-M1 to 10.0.11, 9.0.40 to 9.0.53 and 8.5.60 to 8.5.71 introduced a memory leak. The object introduced to collect metrics for HTTP upgrade connections was not released for WebSocket connections once the connection was closed. This created a memory leak that, over time, could lead to a denial of service via an OutOfMemoryError.

CVE-2021-42340 Affected Apache Tomcat Versions

4 component(s)
Fixed Versions:
10.1.0-M610.0.129.0.548.5.72
Product / Package Ecosystem Affected Versions Fixed Version
org.apache.tomcat:tomcat
Maven
≥ 10.1.0-M1
< 10.1.0-M6
10.1.0-M6
org.apache.tomcat:tomcat
Maven
≥ 10.0.0-M1
< 10.0.12
10.0.12
org.apache.tomcat:tomcat
Maven
≥ 9.0.40
< 9.0.54
9.0.54
org.apache.tomcat:tomcat
Maven
≥ 8.5.60
< 8.5.72
8.5.72

References

NVD — CVE-2021-42340 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-42340
Security Fix Commit FIX COMMIT
https://github.com/apache/tomcat/commit/31d62426645824bdfe076a0c0eafa904d90b4fb9
Security Fix Commit FIX COMMIT
https://github.com/apache/tomcat/commit/80f1438ec45e77a07b96419808971838d259eb47
Security Fix Commit FIX COMMIT
https://github.com/apache/tomcat/commit/d27535bdee95d252418201eb21e9d29476aa6b6a
Security Fix Commit FIX COMMIT
https://github.com/apache/tomcat/commit/d5a6660cba7f51589468937bf3bbad4db7810371
Apache Tomcat Security Information SECURITY
https://www.oracle.com/security-alerts/cpujul2022.html
Apache Tomcat Security Information SECURITY
https://www.oracle.com/security-alerts/cpujan2022.html
Apache Tomcat Security Information SECURITY
https://www.oracle.com/security-alerts/cpuapr2022.html
Apache Tomcat Security Information SECURITY
https://www.debian.org/security/2021/dsa-5009
Apache Tomcat Security Information SECURITY
https://tomcat.apache.org/security-9.html
Apache Tomcat Security Information SECURITY
https://tomcat.apache.org/security-8.html
Apache Tomcat Security Information SECURITY
https://tomcat.apache.org/security-10.html
Apache Tomcat Security Information SECURITY
https://security.netapp.com/advisory/ntap-20211104-0001
Apache Tomcat Security Information SECURITY
https://security.gentoo.org/glsa/202208-34
lists.apache.org/thread.html/r83a35b... WEB
https://lists.apache.org/thread.html/r83a35be60f06aca2065f188ee542b9099695d57ced2e70e0885f905c%40%3Cannounce.tomcat.apache.org%3E
lists.apache.org/thread.html/r8097a2... WEB
https://lists.apache.org/thread.html/r8097a2d1550aa78e585fc77e602b9046e6d4099d8d132497c5387784@%3Ccommits.myfaces.apache.org%3E
kc.mcafee.com/corporate/index WEB
https://kc.mcafee.com/corporate/index?page=content&id=SB10379
Apache Tomcat Source Repository REPOSITORY
https://github.com/apache/tomcat

Frequently Asked Questions

What is CVE-2021-42340?
CVE-2021-42340 is a security vulnerability in Apache Tomcat involving Missing Release of Resource after Effective Lifetime in Apache Tomcat under CWE-772: Missing Release of Resource after Effective Lifetime.
Which Apache Tomcat versions are affected?
Affected versions include releases prior to 10.1.0-M6, 10.0.12, 9.0.54, 8.5.72 across affected packages: org.apache.tomcat:tomcat.
What version fixes CVE-2021-42340?
Upgrading to 10.1.0-M6, 10.0.12, 9.0.54, 8.5.72 (or the latest patched release for your respective branch) resolves the vulnerability.
Is tomcat affected?
Yes, org.apache.tomcat:tomcat is affected in releases prior to 10.1.0-M6, 10.0.12, 9.0.54, 8.5.72. Upgrade your dependency to 10.1.0-M6, 10.0.12, 9.0.54, 8.5.72 or later.
What is the CVSS score of CVE-2021-42340?
CVE-2021-42340 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2021-42340?
CVE-2021-42340 is classified under CWE-772: Missing Release of Resource after Effective Lifetime (The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.).
How can I check Maven dependencies for CVE-2021-42340?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=org.apache.tomcat'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wph7-x527-w3h5",
  "modified" : "2024-03-11T16:36:26Z",
  "published" : "2021-10-15T18:51:34Z",
  "aliases" : [ "CVE-2021-42340" ],
  "summary" : "Missing Release of Resource after Effective Lifetime in Apache Tomcat",
  "details" : "The fix for bug 63362 present in Apache Tomcat 10.1.0-M1 to 10.1.0-M5, 10.0.0-M1 to 10.0.11, 9.0.40 to 9.0.53 and 8.5.60 to 8.5.71 introduced a memory leak. The object introduced to collect metrics for HTTP upgrade connections was not released for WebSocket connections once the connection was closed. This created a memory leak that, over time, could lead to a denial of service via an OutOfMemoryError.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.apache.tomcat:tomcat"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "10.1.0-M1"
      }, {
        "fixed" : "10.1.0-M6"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 10.1.0-M5"
    }
  }, {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.apache.tomcat:tomcat"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "10.0.0-M1"
      }, {
        "fixed" : "10.0.12"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.apache.tomcat:tomcat"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "9.0.40"
      }, {
        "fixed" : "9.0.54"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.apache.tomcat:tomcat"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.5.60"
      }, {
        "fixed" : "8.5.72"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-42340"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/apache/tomcat/commit/31d62426645824bdfe076a0c0eafa904d90b4fb9"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/apache/tomcat/commit/80f1438ec45e77a07b96419808971838d259eb47"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/apache/tomcat/commit/d27535bdee95d252418201eb21e9d29476aa6b6a"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/apache/tomcat/commit/d5a6660cba7f51589468937bf3bbad4db7810371"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujul2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujan2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuapr2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2021/dsa-5009"
  }, {
    "type" : "WEB",
    "url" : "https://tomcat.apache.org/security-9.html"
  }, {
    "type" : "WEB",
    "url" : "https://tomcat.apache.org/security-8.html"
  }, {
    "type" : "WEB",
    "url" : "https://tomcat.apache.org/security-10.html"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20211104-0001"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202208-34"
  }, {
    "type" : "WEB",
    "url" : "https://lists.apache.org/thread.html/r83a35be60f06aca2065f188ee542b9099695d57ced2e70e0885f905c%40%3Cannounce.tomcat.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://lists.apache.org/thread.html/r8097a2d1550aa78e585fc77e602b9046e6d4099d8d132497c5387784@%3Ccommits.myfaces.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://kc.mcafee.com/corporate/index?page=content&id=SB10379"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/apache/tomcat"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-772" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-10-15T13:59:01Z",
    "nvd_published_at" : "2021-10-14T20:15:00Z"
  }
}