GHSA-j756-f273-xhp4: Github.com/nats io/nats server/v2 Remote Code Execution Vulnerability

HIGH
CVSS 7.5
CWE-755 CWE-863
Published
Advisory Summary

GHSA-j756-f273-xhp4 is a HIGH (CVSS 7.5) remote code execution vulnerability (CWE-755: Improper Handling of Exceptional Conditions) affecting Github.com/nats io/nats server/v2 libraries in the Go ecosystem. The issue involves github.com/nats-io/nats-server import token permissions checking not enforced. Remediation is available by upgrading affected packages to version 2.2.0.

GHSA-j756-f273-xhp4 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-j756-f273-xhp4
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-755: Improper Handling of Exceptional Conditions
Affected Product Github.com/nats io/nats server/v2
Package Ecosystem Go
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:H/I:N/A:N).

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 High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix GHSA-j756-f273-xhp4

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.2.0
Upgrade github.com/nats-io/nats-server/v2 to 2.2.0
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 GHSA-j756-f273-xhp4, 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.2.0), 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-755: Improper Handling of Exceptional Conditions, where the product does not handle or incorrectly handles an exceptional condition. 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 advisory is canonically <https://advisories.nats.io/CVE/CVE-2021-3127.txt>) ## Problem Description The NATS server provides for Subjects which are namespaced by Account; all Subjects are supposed to be private to an account, with an Export/Import system used to grant cross-account access to some Subjects. Some Exports are public, such that anyone can import the relevant subjects, and some Exports are private, such that the Import requires a token JWT to prove permission. The JWT library's validation of the bindings in the Import Token incorrectly warned on mismatches, instead of outright rejecting the token. As a result, any account can take an Import token used by any other account and re-use it for themselves because the binding to the importing account is not rejected, and use it to import *any* Subject from the Exporting account, not just the Subject referenced in the Import Token. The NATS account-server system treats account JWTs as semi-public information, such that an attacker can easily enumerate all account JWTs and retrieve all Import Tokens from those account JWTs. The CVE identifier should cover the JWT library repair and the nats-server containing the fixed JWT library, and any other application depending upon the fixed JWT library. ## Affected versions #### JWT library * all versions prior to 2.0.1 * fixed after nats-io/jwt#149 landed (2021-03-14) #### NATS Server * Version 2 prior to 2.2.0 + 2.0.0 through and including 2.1.9 are vulnerable * fixed with nats-io/nats-server@423b79440c (2021-03-14) ## Impact In deployments with untrusted accounts able to update the Account Server with imports, a malicious account can access any Subject from an account which provides Exported Subjects. Abuse of this facility requires the malicious actor to upload their tampered Account JWT to the Account Server, providing the service operator with a data-store which can be scanned for signs of abuse. ## Workaround Deny access to clients to update their account JWT in the account server. ## Solution Upgrade the JWT dependency in any application using it. Upgrade the NATS server if using NATS Accounts (with private Exports; Account owners can create those at any time though). Audit all accounts JWTs to scan for exploit attempts; a Python script to audit the accounts can be found at <https://gist.github.com/philpennock/09d49524ad98043ff11d8a40c2bb0d5a>.

GHSA-j756-f273-xhp4 Affected Github.com/nats io/nats server/v2 Versions

1 component(s)
Fixed Versions:
2.2.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/nats-io/nats-server/v2
Go
< 2.2.0
2.2.0

References

Frequently Asked Questions

What is GHSA-j756-f273-xhp4?
GHSA-j756-f273-xhp4 is a security vulnerability in Github.com/nats io/nats server/v2 involving github.com/nats-io/nats-server Import token permissions checking not enforced under CWE-755: Improper Handling of Exceptional Conditions.
Which Github.com/nats io/nats server/v2 versions are affected?
Affected versions include releases prior to 2.2.0 across affected packages: github.com/nats-io/nats-server/v2.
What version fixes GHSA-j756-f273-xhp4?
Upgrading to 2.2.0 (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.2.0. Upgrade your dependency to 2.2.0 or later.
What is the CVSS score of GHSA-j756-f273-xhp4?
GHSA-j756-f273-xhp4 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:H/I:N/A:N.
What CWE is associated with GHSA-j756-f273-xhp4?
GHSA-j756-f273-xhp4 is classified under CWE-755: Improper Handling of Exceptional Conditions (The product does not handle or incorrectly handles an exceptional condition.).
How can I check Go dependencies for GHSA-j756-f273-xhp4?
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-j756-f273-xhp4",
  "modified" : "2024-05-21T15:22:51Z",
  "published" : "2021-05-21T16:22:20Z",
  "aliases" : [ ],
  "summary" : "github.com/nats-io/nats-server Import token permissions checking not enforced",
  "details" : "(This advisory is canonically <https://advisories.nats.io/CVE/CVE-2021-3127.txt>)\n\n## Problem Description\n\nThe NATS server provides for Subjects which are namespaced by Account; all Subjects are supposed to be private to an account, with an Export/Import system used to grant cross-account access to some Subjects.  Some Exports are public, such that anyone can import the relevant subjects, and some Exports are private, such that the Import requires a token JWT to prove permission.\n\nThe JWT library's validation of the bindings in the Import Token incorrectly warned on mismatches, instead of outright rejecting the token.\n\nAs a result, any account can take an Import token used by any other account and re-use it for themselves because the binding to the importing account is not rejected, and use it to import *any* Subject from the Exporting account, not just the Subject referenced in the Import Token.\n\nThe NATS account-server system treats account JWTs as semi-public information, such that an attacker can easily enumerate all account JWTs and retrieve all Import Tokens from those account JWTs.\n\nThe CVE identifier should cover the JWT library repair and the nats-server containing the fixed JWT library, and any other application depending upon the fixed JWT library.\n\n\n## Affected versions\n\n#### JWT library\n\n * all versions prior to 2.0.1\n * fixed after nats-io/jwt#149 landed (2021-03-14)\n\n#### NATS Server\n\n * Version 2 prior to 2.2.0\n   + 2.0.0 through and including 2.1.9 are vulnerable\n * fixed with nats-io/nats-server@423b79440c (2021-03-14)\n\n\n## Impact\n\nIn deployments with untrusted accounts able to update the Account Server with imports, a malicious account can access any Subject from an account which provides Exported Subjects.\n\nAbuse of this facility requires the malicious actor to upload their tampered Account JWT to the Account Server, providing the service operator with a data-store which can be scanned for signs of abuse.\n\n\n## Workaround\n\nDeny access to clients to update their account JWT in the account server.\n\n\n## Solution\n\nUpgrade the JWT dependency in any application using it.\n\nUpgrade the NATS server if using NATS Accounts (with private Exports; Account owners can create those at any time though).\n\nAudit all accounts JWTs to scan for exploit attempts; a Python script to audit the accounts can be found at <https://gist.github.com/philpennock/09d49524ad98043ff11d8a40c2bb0d5a>.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/nats-io/nats-server/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/jwt/security/advisories/GHSA-62mh-w5cv-p88c"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-server/security/advisories/GHSA-j756-f273-xhp4"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-3127"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/nats-server/commit/423b79440c80c863de9f4e20548504e6c5d5e403"
  }, {
    "type" : "WEB",
    "url" : "https://advisories.nats.io/CVE/CVE-2021-3127.txt"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nats-io/nats-server"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-755", "CWE-863" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-05-20T21:01:49Z",
    "nvd_published_at" : null
  }
}