CVE-2021-3127: Github.com/nats io/jwt Nats-io/jwt Not Enforcing Checking Of Vulnerability

CRITICAL
Advisory Identifier: GHSA-62mh-w5cv-p88c
CWE-863
Published
Advisory Summary

CVE-2021-3127 is a CRITICAL nats-io/jwt not enforcing checking of vulnerability (CWE-863: Incorrect Authorization) affecting Github.com/nats io/jwt libraries in the Go ecosystem. The issue involves nats-io/jwt not enforcing checking of import token permissions. Remediation is available by upgrading affected packages to version 2.0.1.

CVE-2021-3127 at a Glance

CVE Identifier CVE-2021-3127
GHSA Identifier GHSA-62mh-w5cv-p88c
Severity CRITICAL
CVSS v3.1 Base Score N/A
CWE Classification CWE-863: Incorrect Authorization
Affected Product Github.com/nats io/jwt
Package Ecosystem Go
Published Date
Last Updated

How to Fix CVE-2021-3127

To remediate this vulnerability, upgrade all affected Github.com/nats io/jwt 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/jwt fixed: Latest secure release
Upgrade github.com/nats-io/jwt to Latest secure release
github.com/nats-io/jwt/v2 fixed: 2.0.1
Upgrade github.com/nats-io/jwt/v2 to 2.0.1
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/jwt

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-3127, inspect your project dependencies for Github.com/nats io/jwt:

inspect dependencies for github.com/nats-io/jwt

Analyze the terminal output to locate any version of Github.com/nats io/jwt in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.1), 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-863: Incorrect Authorization, where the product performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check. In Github.com/nats io/jwt, 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>.

CVE-2021-3127 Affected Github.com/nats io/jwt Versions

2 component(s)
Fixed Versions:
2.0.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/nats-io/jwt
Go
≤ 1.2.2
github.com/nats-io/jwt/v2
Go
< 2.0.1
2.0.1

References

Frequently Asked Questions

What is CVE-2021-3127?
CVE-2021-3127 is a security vulnerability in Github.com/nats io/jwt involving nats-io/jwt not enforcing checking of Import token permissions under CWE-863: Incorrect Authorization.
Which Github.com/nats io/jwt versions are affected?
Affected versions include releases prior to 2.0.1 across affected packages: github.com/nats-io/jwt, github.com/nats-io/jwt/v2.
What version fixes CVE-2021-3127?
Upgrading to 2.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/nats-io/jwt affected?
Yes, github.com/nats-io/jwt is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
Is github.com/nats-io/jwt/v2 affected?
Yes, github.com/nats-io/jwt/v2 is affected in releases prior to 2.0.1. Upgrade your dependency to 2.0.1 or later.
What CWE is associated with CVE-2021-3127?
CVE-2021-3127 is classified under CWE-863: Incorrect Authorization (The product performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check.).
How can I check Go dependencies for CVE-2021-3127?
Run the dependency tree command: 'inspect dependencies for github.com/nats-io/jwt'. 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-62mh-w5cv-p88c",
  "modified" : "2024-05-21T15:22:54Z",
  "published" : "2022-02-15T00:42:28Z",
  "aliases" : [ "CVE-2021-3127" ],
  "summary" : "nats-io/jwt not enforcing checking of Import token permissions",
  "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\nrelevant 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\nimporting 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" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/nats-io/jwt"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "1.2.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/nats-io/jwt/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.0.1"
      } ]
    } ]
  } ],
  "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" : "WEB",
    "url" : "https://github.com/nats-io/jwt/pull/149"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nats-io/jwt/commit/6c72fdd73e82fa9ebb151d84773baf4e9164c4ab"
  }, {
    "type" : "WEB",
    "url" : "https://advisories.nats.io/CVE/CVE-2021-3127.txt"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nats-io/jwt"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-863" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-05-20T20:58:15Z",
    "nvd_published_at" : null
  }
}