Vulnerabilities in pkg:maven/io.metersphere/metersphere

PACKAGE
Advisory Identifier: GHSA-9p62-x3c5-hr5p
Advisory Summary

CVE-2022-46178 is a HIGH (CVSS 7.4) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Metersphere libraries in the Maven ecosystem. The issue involves path traversal in meterspere leads to upload file to any path. Remediation is available by upgrading affected packages to version 2.5.1.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:maven/io.metersphere/metersphere

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:maven/io.metersphere/metersphere. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-9p62-x3c5-hr5p CVE-2022-46178 HIGH Path Traversal In MeterSpere leads to upload file to any path

CVE-2022-46178 at a Glance

CVE Identifier CVE-2022-46178
GHSA Identifier GHSA-9p62-x3c5-hr5p
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Metersphere
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 7.4

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

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

How to Fix CVE-2022-46178

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

io.metersphere:metersphere fixed: 2.5.1
<dependency>
    <groupId>io.metersphere</groupId>
    <artifactId>metersphere</artifactId>
    <version>2.5.1</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=io.metersphere

How to Check if You Are Affected

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

mvn dependency:tree -Dincludes=io.metersphere

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

Note: The mvn dependency:tree -Dincludes=io.metersphere 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 Metersphere, 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

### Summary MeterSphere allow users to upload file, but not check the file name, may lead to upload file to any path if the file name in upload request is falsified. ### Details Metersphere's [`FileUtils.java`](https://github.com/metersphere/metersphere/blob/v2.5.0/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java#L57) didn't check the filePath. ```java public static void createFile(String filePath, byte[] fileBytes) { File file = new File(filePath); if (file.exists()) { file.delete(); } try { File dir = file.getParentFile(); if (!dir.exists()) { dir.mkdirs(); } file.createNewFile(); } catch (Exception e) { LogUtil.error(e); } try (InputStream in = new ByteArrayInputStream(fileBytes); OutputStream out = new FileOutputStream(file)) { final int MAX = 4096; byte[] buf = new byte[MAX]; for (int bytesRead = in.read(buf, 0, MAX); bytesRead != -1; bytesRead = in.read(buf, 0, MAX)) { out.write(buf, 0, bytesRead); } } catch (IOException e) { LogUtil.error(e); MSException.throwException(Translator.get("upload_fail")); } } ``` ### Patches The vulnerability has been fixed in [v2.5.1](https://github.com/metersphere/metersphere/releases/tag/v2.5.1). https://github.com/metersphere/metersphere/commit/3a890eeeb8a6b0887927c876a73bdb3a99a82138 : add validation for file name. ### Workarounds It is recommended to upgrade the version to [v2.5.1](https://github.com/metersphere/metersphere/releases/tag/v2.5.1). ### For more information If you have any questions or comments about this advisory, please [open an issue](https://github.com/metersphere/metersphere/issues).

CVE-2022-46178 Affected Metersphere Versions

1 component(s)
Fixed Versions:
2.5.1
Product / Package Ecosystem Affected Versions Fixed Version
io.metersphere:metersphere
Maven
< 2.5.1
2.5.1

References

Frequently Asked Questions

What is CVE-2022-46178?
CVE-2022-46178 is a security vulnerability in Metersphere involving Path Traversal In MeterSpere leads to upload file to any path under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Metersphere versions are affected?
Affected versions include releases prior to 2.5.1 across affected packages: io.metersphere:metersphere.
What version fixes CVE-2022-46178?
Upgrading to 2.5.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is metersphere affected?
Yes, io.metersphere:metersphere is affected in releases prior to 2.5.1. Upgrade your dependency to 2.5.1 or later.
What is the CVSS score of CVE-2022-46178?
CVE-2022-46178 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:L.
What CWE is associated with CVE-2022-46178?
CVE-2022-46178 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-46178?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=io.metersphere'. 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-9p62-x3c5-hr5p",
  "modified" : "2022-12-30T18:03:47Z",
  "published" : "2022-12-30T18:03:47Z",
  "aliases" : [ "CVE-2022-46178" ],
  "summary" : "Path Traversal In MeterSpere leads to upload file to any path",
  "details" : "### Summary\n\nMeterSphere allow users to upload file, but not check the file name, may lead to upload file to any path if the file name in upload request is falsified.\n\n### Details\n\nMetersphere's [`FileUtils.java`](https://github.com/metersphere/metersphere/blob/v2.5.0/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java#L57) didn't check the filePath.\n\n```java\n    public static void createFile(String filePath, byte[] fileBytes) {\n        File file = new File(filePath);\n        if (file.exists()) {\n            file.delete();\n        }\n        try {\n            File dir = file.getParentFile();\n            if (!dir.exists()) {\n                dir.mkdirs();\n            }\n            file.createNewFile();\n        } catch (Exception e) {\n            LogUtil.error(e);\n        }\n\n        try (InputStream in = new ByteArrayInputStream(fileBytes); OutputStream out = new FileOutputStream(file)) {\n            final int MAX = 4096;\n            byte[] buf = new byte[MAX];\n            for (int bytesRead = in.read(buf, 0, MAX); bytesRead != -1; bytesRead = in.read(buf, 0, MAX)) {\n                out.write(buf, 0, bytesRead);\n            }\n        } catch (IOException e) {\n            LogUtil.error(e);\n            MSException.throwException(Translator.get(\"upload_fail\"));\n        }\n    }\n```\n\n### Patches\n\nThe vulnerability has been fixed in [v2.5.1](https://github.com/metersphere/metersphere/releases/tag/v2.5.1).\n\nhttps://github.com/metersphere/metersphere/commit/3a890eeeb8a6b0887927c876a73bdb3a99a82138 : add validation for file name.\n\n### Workarounds\n\nIt is recommended to upgrade the version to [v2.5.1](https://github.com/metersphere/metersphere/releases/tag/v2.5.1).\n\n### For more information\n\nIf you have any questions or comments about this advisory, please [open an issue](https://github.com/metersphere/metersphere/issues).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "io.metersphere:metersphere"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.5.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/metersphere/metersphere/security/advisories/GHSA-9p62-x3c5-hr5p"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-46178"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/metersphere/metersphere"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/metersphere/metersphere/blob/v2.5.0/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java#L5"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/metersphere/metersphere/releases/tag/v2.5.1"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-12-30T18:03:47Z",
    "nvd_published_at" : "2022-12-29T19:15:00Z"
  }
}