CVE-2022-26652: Github.com/nats io/nats server/v2 Arbitrary File Write Vulnerability
HIGHCVE-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
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).
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.
Upgrade github.com/nats-io/nats-server/v2 to 2.7.4
Upgrade github.com/nats-io/nats-streaming-server to 0.24.3
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
CVE-2022-26652 Affected Github.com/nats io/nats server/v2 Versions
2 component(s)| 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?
Which Github.com/nats io/nats server/v2 versions are affected?
What version fixes CVE-2022-26652?
Is github.com/nats-io/nats-server/v2 affected?
Is github.com/nats-io/nats-streaming-server affected?
What is the CVSS score of CVE-2022-26652?
What CWE is associated with CVE-2022-26652?
How can I check Go dependencies for CVE-2022-26652?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}