CVE-2022-26652: Github.com/nats io/nats server/v2 Arbitrary File Write Vulnerability

HIGH
Advisory Identifier: GHSA-6h3m-36w8-hv68
CVSS 6.5
CWE-22
Published
Advisory Summary

CVE-2022-26652 is a HIGH (CVSS 6.5) arbitrary file write vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Github.com/nats io/nats server/v2 libraries in the Go ecosystem. The issue involves arbitrary file write in nats-server. Remediation is available by upgrading affected packages to version 2.7.4, 0.24.3.

CVE-2022-26652 at a Glance

CVE Identifier CVE-2022-26652
GHSA Identifier GHSA-6h3m-36w8-hv68
Severity HIGH
CVSS v3.1 Base Score 6.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Github.com/nats io/nats server/v2
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 6.5

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:U/C:N/I:H/A:N).

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

How to Fix CVE-2022-26652

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

github.com/nats-io/nats-server/v2 fixed: 2.7.4
Upgrade github.com/nats-io/nats-server/v2 to 2.7.4
github.com/nats-io/nats-streaming-server fixed: 0.24.3
Upgrade github.com/nats-io/nats-streaming-server to 0.24.3
Verify Direct and Transitive Dependencies

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

inspect dependencies for github.com/nats-io/nats-server/v2

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-26652, inspect your project dependencies for Github.com/nats io/nats server/v2:

inspect dependencies for github.com/nats-io/nats-server/v2

Analyze the terminal output to locate any version of Github.com/nats io/nats server/v2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.7.4), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

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 Github.com/nats io/nats server/v2, 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

(This document is canonically: <https://advisories.nats.io/CVE/CVE-2022-26652.txt>) ## Background NATS.io is a high performance open source pub-sub distributed communication technology, built for the cloud, on-premise, IoT, and edge computing. JetStream is the optional RAFT-based resilient persistent feature of NATS. ## Problem Description The JetStream streams can be backed up and restored via NATS. The backup format is a tar archive file. Inadequate checks on the filenames within the archive file permit a so-called "Zip Slip" attack in the stream restore. NATS nats-server through 2022-03-09 (fixed in release 2.7.4) did not correctly sanitize elements of the archive file, thus a user of NATS could cause the NATS server to write arbitrary content to an attacker-controlled filename. ## Affected versions NATS Server: * 2.2.0 up to and including 2.7.3. + Introduced with JetStream Restore functionality * Fixed with nats-io/nats-server: 2.7.4 * Docker image: nats <https://hub.docker.com/_/nats> * NB users of OS package files from our releases: a change in goreleaser defaults, discovered late in the release process, moved the install directory from /usr/local/bin to /usr/bin; we are evaluating the correct solution for subsequent releases, but not recutting this release. NATS Streaming Server * 0.15.0 up to and including 0.24.2 * Fixed with nats-io/nats-streaming-server: 0.24.3 * Embeds a nats-server, but this server is the old approach which JetStream replaces, so unlikely (but not impossible) to be configured with JS support ## Workarounds * Disable JetStream for untrusted users. * If only one NATS account uses JetStream, such that cross-user attacks are not an issue, and any user in that account with access to the JetStream API is fully trusted anyway, then appropriate sandboxing techniques will prevent exploit. + Eg, with systemd, the supplied util/nats-server-hardened.service example configuration demonstrates that NATS runs fine as an unprivileged user under ProtectSystem=strict and PrivateTmp=true restrictions; by only opening a ReadWritePaths hole for the JetStream storage area, the impact of this vulnerability is limited. ## Solution Upgrade the NATS server to at least 2.7.4. We fully support the util/nats-server-hardened.service configuration for running a NATS server and encourage this approach. ## Credits This issue was reported (on 2022-03-07) to the NATS Maintainers by Yiming Xiang, TIANJI LAB of NSFOCUS. Thank you / 谢谢你!

CVE-2022-26652 Affected Github.com/nats io/nats server/v2 Versions

2 component(s)
Fixed Versions:
2.7.40.24.3
Product / Package Ecosystem Affected Versions Fixed Version
github.com/nats-io/nats-server/v2
Go
≥ 2.2.0
< 2.7.4
2.7.4
github.com/nats-io/nats-streaming-server
Go
≥ 0.15.0
< 0.24.3
0.24.3

References

Frequently Asked Questions

What is CVE-2022-26652?
CVE-2022-26652 is a security vulnerability in Github.com/nats io/nats server/v2 involving Arbitrary file write in nats-server under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Github.com/nats io/nats server/v2 versions are affected?
Affected versions include releases prior to 2.7.4, 0.24.3 across affected packages: github.com/nats-io/nats-server/v2, github.com/nats-io/nats-streaming-server.
What version fixes CVE-2022-26652?
Upgrading to 2.7.4, 0.24.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/nats-io/nats-server/v2 affected?
Yes, github.com/nats-io/nats-server/v2 is affected in releases prior to 2.7.4. Upgrade your dependency to 2.7.4 or later.
Is github.com/nats-io/nats-streaming-server affected?
Yes, github.com/nats-io/nats-streaming-server is affected in releases prior to 0.24.3. Upgrade your dependency to 0.24.3 or later.
What is the CVSS score of CVE-2022-26652?
CVE-2022-26652 has a CVSS v3.1 base score of 6.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2022-26652?
CVE-2022-26652 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 Go dependencies for CVE-2022-26652?
Run the dependency tree command: 'inspect dependencies for github.com/nats-io/nats-server/v2'. 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-6h3m-36w8-hv68",
  "modified" : "2022-03-24T00:21:10Z",
  "published" : "2022-03-10T22:07:30Z",
  "aliases" : [ "CVE-2022-26652" ],
  "summary" : "Arbitrary file write in nats-server",
  "details" : "(This document is canonically: <https://advisories.nats.io/CVE/CVE-2022-26652.txt>)\n\n## Background\n\nNATS.io is a high performance open source pub-sub distributed communication technology, built for the cloud, on-premise, IoT, and edge computing.\n\nJetStream is the optional RAFT-based resilient persistent feature of NATS.\n\n\n## Problem Description\n\nThe JetStream streams can be backed up and restored via NATS. The backup format is a tar archive file.  Inadequate checks on the filenames within the archive file permit a so-called \"Zip Slip\" attack in the stream restore.\n\nNATS nats-server through 2022-03-09 (fixed in release 2.7.4) did not correctly sanitize elements of the archive file, thus a user of NATS\ncould cause the NATS server to write arbitrary content to an attacker-controlled filename.\n\n\n## Affected versions\n\nNATS Server:\n * 2.2.0 up to and including 2.7.3.\n   + Introduced with JetStream Restore functionality\n * Fixed with nats-io/nats-server: 2.7.4\n * Docker image:  nats <https://hub.docker.com/_/nats>\n * NB users of OS package files from our releases: a change in goreleaser defaults, discovered late in the release process, moved the install directory from /usr/local/bin to /usr/bin; we are evaluating the correct solution for subsequent releases, but not recutting this release.\n\nNATS Streaming Server\n * 0.15.0 up to and including 0.24.2\n * Fixed with nats-io/nats-streaming-server: 0.24.3\n * Embeds a nats-server, but this server is the old approach which JetStream replaces, so unlikely (but not impossible) to be\n   configured with JS support\n\n\n## Workarounds\n\n * Disable JetStream for untrusted users.\n * If only one NATS account uses JetStream, such that cross-user attacks are not an issue, and any user in that account with access to the JetStream API is fully trusted anyway, then appropriate sandboxing techniques will prevent exploit.\n   + Eg, with systemd, the supplied util/nats-server-hardened.service example configuration demonstrates that NATS runs fine as an unprivileged user under ProtectSystem=strict and PrivateTmp=true restrictions; by only opening a ReadWritePaths hole for the JetStream storage area, the impact of this vulnerability is limited.\n\n\n## Solution\n\nUpgrade the NATS server to at least 2.7.4.\n\nWe fully support the util/nats-server-hardened.service configuration for running a NATS server and encourage this approach.\n\n\n## Credits\n\nThis issue was reported (on 2022-03-07) to the NATS Maintainers by\nYiming Xiang, TIANJI LAB of NSFOCUS.  \nThank you / 谢谢你!\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/nats-io/nats-server/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.2.0"
      }, {
        "fixed" : "2.7.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/nats-io/nats-streaming-server"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.15.0"
      }, {
        "fixed" : "0.24.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-server/security/advisories/GHSA-6h3m-36w8-hv68"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-26652"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-server/pull/2917"
  }, {
    "type" : "WEB",
    "url" : "https://advisories.nats.io/CVE/CVE-2022-26652.txt"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nats-io/nats-server"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-server/releases"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-server/releases/tag/v2.7.4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-streaming-server/releases/tag/v0.24.3"
  }, {
    "type" : "WEB",
    "url" : "http://www.openwall.com/lists/oss-security/2022/03/10/1"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-03-10T22:07:30Z",
    "nvd_published_at" : "2022-03-10T17:47:00Z"
  }
}