CVE-2022-4065: Testng Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-rc2q-x9mf-w3vf
CVSS 7.8
CWE-22
Published
Advisory Summary

CVE-2022-4065 is a HIGH (CVSS 7.8) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Testng libraries in the Maven ecosystem. The issue involves testng is vulnerable to path traversal. Remediation is available by upgrading affected packages to version 7.5.1, 7.7.0.

CVE-2022-4065 at a Glance

CVE Identifier CVE-2022-4065
GHSA Identifier GHSA-rc2q-x9mf-w3vf
Severity HIGH
CVSS v3.1 Base Score 7.8
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Testng
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 7.8

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

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

How to Fix CVE-2022-4065

To remediate this vulnerability, upgrade all affected Testng 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.testng:testng fixed: 7.5.1
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.5.1</version>
</dependency>
org.testng:testng fixed: 7.7.0
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.7.0</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.testng

How to Check if You Are Affected

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

mvn dependency:tree -Dincludes=org.testng

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

Note: The mvn dependency:tree -Dincludes=org.testng 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-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Testng, 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

### Impact Affected by this vulnerability is the function `testngXmlExistsInJar` of the file `testng-core/src/main/java/org/testng/JarFileUtils.java` of the component `XML File Parser`. The manipulation leads to path traversal only for `.xml`, `.yaml` and `.yml` files by default. The attack implies running an unsafe test JAR. However since that JAR can also contain executable code itself, the path traversal is unlikely to be the main attack. ### Patches A patch is available in [version 7.7.0](https://github.com/cbeust/testng/releases/tag/7.7.0) at commit 9150736cd2c123a6a3b60e6193630859f9f0422b. It is recommended to apply a patch to fix this issue. The patch was pushed into the master branch but no releases have yet been made with the patch included. A backport of the fix is available in [version 7.5.1]((https://github.com/cbeust/testng/releases/tag/7.5.1) for Java 8 projects. ### Workaround * Specify which tests to run when invoking TestNG by configuring them on the CLI or in the build tool controlling the run. * Do not run tests with untrusted JARs on the classpath, this includes pull requests on open source projects.

CVE-2022-4065 Affected Testng Versions

2 component(s)
Fixed Versions:
7.5.17.7.0
Product / Package Ecosystem Affected Versions Fixed Version
org.testng:testng
Maven
≥ 6.13
< 7.5.1
7.5.1
org.testng:testng
Maven
≥ 7.6.0
< 7.7.0
7.7.0

References

Frequently Asked Questions

What is CVE-2022-4065?
CVE-2022-4065 is a security vulnerability in Testng involving TestNG is vulnerable to Path Traversal under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Testng versions are affected?
Affected versions include releases prior to 7.5.1, 7.7.0 across affected packages: org.testng:testng.
What version fixes CVE-2022-4065?
Upgrading to 7.5.1, 7.7.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is testng affected?
Yes, org.testng:testng is affected in releases prior to 7.5.1, 7.7.0. Upgrade your dependency to 7.5.1, 7.7.0 or later.
What is the CVSS score of CVE-2022-4065?
CVE-2022-4065 has a CVSS v3.1 base score of 7.8 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-4065?
CVE-2022-4065 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check Maven dependencies for CVE-2022-4065?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=org.testng'. 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-rc2q-x9mf-w3vf",
  "modified" : "2023-05-09T17:53:32Z",
  "published" : "2022-11-19T21:30:25Z",
  "aliases" : [ "CVE-2022-4065" ],
  "summary" : "TestNG is vulnerable to Path Traversal",
  "details" : "### Impact\n\nAffected by this vulnerability is the function `testngXmlExistsInJar` of the file `testng-core/src/main/java/org/testng/JarFileUtils.java` of the component `XML File Parser`.\n\nThe manipulation leads to path traversal only for `.xml`, `.yaml` and `.yml` files by default. The attack implies running an unsafe test JAR. However since that JAR can also contain executable code itself, the path traversal is unlikely to be the main attack.\n\n### Patches\n\nA patch is available in [version 7.7.0](https://github.com/cbeust/testng/releases/tag/7.7.0) at commit 9150736cd2c123a6a3b60e6193630859f9f0422b. It is recommended to apply a patch to fix this issue. The patch was pushed into the master branch but no releases have yet been made with the patch included.\n\nA backport of the fix is available in [version 7.5.1]((https://github.com/cbeust/testng/releases/tag/7.5.1) for Java 8 projects.\n\n### Workaround\n\n* Specify which tests to run when invoking TestNG by configuring them on the CLI or in the build tool controlling the run.\n* Do not run tests with untrusted JARs on the classpath, this includes pull requests on open source projects.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.testng:testng"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.13"
      }, {
        "fixed" : "7.5.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.testng:testng"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "7.6.0"
      }, {
        "fixed" : "7.7.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-4065"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/cbeust/testng/pull/1596"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/cbeust/testng/pull/2806"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/testng-team/testng/pull/2899"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/cbeust/testng/commit/9150736cd2c123a6a3b60e6193630859f9f0422b"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/cbeust/testng"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/cbeust/testng/releases/tag/7.7.0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/cbeust/testng/releases/tag/7.7.1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/testng-team/testng/releases/tag/7.5.1"
  }, {
    "type" : "WEB",
    "url" : "https://vuldb.com/?ctiid.214027"
  }, {
    "type" : "WEB",
    "url" : "https://vuldb.com/?id.214027"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-12-02T22:31:06Z",
    "nvd_published_at" : "2022-11-19T19:15:00Z"
  }
}