Vulnerabilities in pkg:golang/github.com/lestrrat-go/jwx/v2

PACKAGE
Advisory Identifier: GHSA-hj3v-m684-v259
Advisory Summary

CVE-2024-28122 is a MODERATE (CVSS 6.8) denial of service vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting Github.com/lestrrat go/jwx/v2 libraries in the Go ecosystem. The issue involves jwx vulnerable to a denial of service attack using compressed jwe message. Remediation is available by upgrading affected packages to version 2.0.21, 1.2.29.

4 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:golang/github.com/lestrrat-go/jwx/v2

4 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:golang/github.com/lestrrat-go/jwx/v2. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-hj3v-m684-v259 CVE-2024-28122 MODERATE JWX vulnerable to a denial of service attack using compressed JWE message
GHSA-pvcr-v8j8-j5q3 CVE-2024-21664 MODERATE Parsing JSON serialized payload without protected field can lead to segfault
GHSA-7f9x-gw85-8grf CVE-2023-49290 MODERATE lestrrat-go/jwx's malicious parameters in JWE can cause a DOS
GHSA-rm8v-mxj3-5rmq - MODERATE github.com/lestrrat-go/jwx vulnerable to Potential Padding Oracle Attack

CVE-2024-28122 at a Glance

CVE Identifier CVE-2024-28122
GHSA Identifier GHSA-hj3v-m684-v259
Severity MODERATE
CVSS v3.1 Base Score 6.8
CWE Classification CWE-400: Uncontrolled Resource Consumption
Affected Product Github.com/lestrrat go/jwx/v2
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 6.8

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

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

How to Fix CVE-2024-28122

To remediate this vulnerability, upgrade all affected Github.com/lestrrat go/jwx/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/lestrrat-go/jwx/v2 fixed: 2.0.21
Upgrade github.com/lestrrat-go/jwx/v2 to 2.0.21
github.com/lestrrat-go/jwx fixed: 1.2.29
Upgrade github.com/lestrrat-go/jwx to 1.2.29
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/lestrrat-go/jwx/v2

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-28122, inspect your project dependencies for Github.com/lestrrat go/jwx/v2:

inspect dependencies for github.com/lestrrat-go/jwx/v2

Analyze the terminal output to locate any version of Github.com/lestrrat go/jwx/v2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.21), 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-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In Github.com/lestrrat go/jwx/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

### Summary This vulnerability allows an attacker with a trusted public key to cause a Denial-of-Service (DoS) condition by crafting a malicious JSON Web Encryption (JWE) token with an exceptionally high compression ratio. When this token is processed by the recipient, it results in significant memory allocation and processing time during decompression. ### Details **The attacker needs to obtain a valid public key to compress the payload**. It needs to be valid so that the recipient can use to successfully decompress the payload. Furthermore in context JWT processing in the v2 versions, the recipient must explicitly allow JWE handling . The attacker then crafts a message with high compression ratio, e.g. a payload with very high frequency of repeating patterns that can decompress to a much larger size. If the payload is large enough, recipient who is decompressing the data will have to allocate a large amount of memory, which then can lead to a denial of service. The original report includes a reference to [1], but there are some very subtle differences between this library and the aforementioned issue. The most important aspect is that the referenced issue focuses on JWT processing, whereas this library is intentionally divided into parts that comprise JOSE, i.e. JWT, JWS, JWE, JWK. In particular, v2 of this library does not attempt to handle JWT payload enveloped in a JWE message automatically (v1 attempted to do this automatically, but it was never stable). Reflecting this subtle difference, the approach taken to mitigate this vulnerability is slightly different from the referenced issue. The referenced issue limits the size of JWT when parsing, but the fixes for this library limits the maximum size of the decompressed data when decrypting JWE messages. Therefore the fix in this library is applicable regardless of the usage context, and a limit is now imposed on the size of the message that our JWE implementation can handle. ### Proof of Concept Modified from the original report to fit the vulnerability better: ```go // The value below just needs to be "large enough" so that the it puts enough strain on the // recipient's environment. The value below is a safe size on my machine to run the test // without causing problems. When you increase the payload size, at some point the processing // will be slow enough to virtually freeze the program or cause a memory allocation error const payloadSize = 1 << 31 privkey, err := rsa.GenerateKey(rand.Reader, 2048) require.NoError(t, err, `rsa.GenerateKey should succeed`) pubkey := &privkey.PublicKey payload := strings.Repeat("x", payloadSize) encrypted, err := jwe.Encrypt([]byte(payload), jwe.WithKey(jwa.RSA_OAEP, pubkey), jwe.WithContentEncryption("A128CBC-HS256"), jwe.WithCompress(jwa.Deflate)) require.NoError(t, err, `jwe.Encrypt should succeed`) _, err = jwe.Decrypt(encrypted, jwe.WithKey(jwa.RSA_OAEP, privkey)) // Will be allocating large amounts of memory require.Error(t, err, `jwe.Decrypt should fail`) ``` ### References [1] [CVE-2024-21319](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/security/advisories/GHSA-8g9c-28fc-mcx2)

CVE-2024-28122 Affected Github.com/lestrrat go/jwx/v2 Versions

2 component(s)
Fixed Versions:
2.0.211.2.29
Product / Package Ecosystem Affected Versions Fixed Version
github.com/lestrrat-go/jwx/v2
Go
< 2.0.21
2.0.21
github.com/lestrrat-go/jwx
Go
< 1.2.29
1.2.29

References

Frequently Asked Questions

What is CVE-2024-28122?
CVE-2024-28122 is a security vulnerability in Github.com/lestrrat go/jwx/v2 involving JWX vulnerable to a denial of service attack using compressed JWE message under CWE-400: Uncontrolled Resource Consumption.
Which Github.com/lestrrat go/jwx/v2 versions are affected?
Affected versions include releases prior to 2.0.21, 1.2.29 across affected packages: github.com/lestrrat-go/jwx/v2, github.com/lestrrat-go/jwx.
What version fixes CVE-2024-28122?
Upgrading to 2.0.21, 1.2.29 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/lestrrat-go/jwx/v2 affected?
Yes, github.com/lestrrat-go/jwx/v2 is affected in releases prior to 2.0.21. Upgrade your dependency to 2.0.21 or later.
Is github.com/lestrrat-go/jwx affected?
Yes, github.com/lestrrat-go/jwx is affected in releases prior to 1.2.29. Upgrade your dependency to 1.2.29 or later.
What is the CVSS score of CVE-2024-28122?
CVE-2024-28122 has a CVSS v3.1 base score of 6.8 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:N/I:N/A:H.
What CWE is associated with CVE-2024-28122?
CVE-2024-28122 is classified under CWE-400: Uncontrolled Resource Consumption (The product does not properly control the allocation and maintenance of a limited resource.).
How can I check Go dependencies for CVE-2024-28122?
Run the dependency tree command: 'inspect dependencies for github.com/lestrrat-go/jwx/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-hj3v-m684-v259",
  "modified" : "2024-03-11T03:37:15Z",
  "published" : "2024-03-08T15:06:53Z",
  "aliases" : [ "CVE-2024-28122" ],
  "summary" : "JWX vulnerable to a denial of service attack using compressed JWE message",
  "details" : "### Summary\nThis vulnerability allows an attacker with a trusted public key to cause a Denial-of-Service (DoS) condition by crafting a malicious JSON Web Encryption (JWE) token with an exceptionally high compression ratio. When this token is processed by the recipient, it results in significant memory allocation and processing time during decompression.\n\n### Details\n\n**The attacker needs to obtain a valid public key to compress the payload**. It needs to be valid so that the recipient can use to successfully decompress the payload. Furthermore in context JWT processing in the v2 versions, the recipient must explicitly allow JWE handling .\n\nThe attacker then crafts a message with high compression ratio, e.g. a payload with very high frequency of repeating patterns that can decompress to a much larger size.  If the payload is large enough, recipient who is decompressing the data will have to allocate a large amount of memory, which then can lead to a denial of service.\n\nThe original report includes a reference to [1], but there are some very subtle differences between this library and the aforementioned issue. The most important aspect is that the referenced issue focuses on JWT processing, whereas this library is intentionally divided into parts that comprise JOSE, i.e. JWT, JWS, JWE, JWK. In particular, v2 of this library does not attempt to handle JWT payload enveloped in a JWE message automatically (v1 attempted to do this automatically, but it was never stable).\n\nReflecting this subtle difference, the approach taken to mitigate this vulnerability is slightly different from the referenced issue. The referenced issue limits the size of JWT when parsing, but the fixes for this library limits the maximum size of the decompressed data when decrypting JWE messages. Therefore the fix in this library is applicable regardless of the usage context, and a limit is now imposed on the size of the message that our JWE implementation can handle.\n\n### Proof of Concept\n\nModified from the original report to fit the vulnerability better:\n\n```go\n// The value below just needs to be \"large enough\" so that the it puts enough strain on the\n// recipient's environment. The value below is a safe size on my machine to run the test\n// without causing problems. When you increase the payload size, at some point the processing\n// will be slow enough to virtually freeze the program or cause a memory allocation error\nconst payloadSize = 1 << 31\n\nprivkey, err := rsa.GenerateKey(rand.Reader, 2048)\nrequire.NoError(t, err, `rsa.GenerateKey should succeed`)\npubkey := &privkey.PublicKey\npayload := strings.Repeat(\"x\", payloadSize)\n\nencrypted, err := jwe.Encrypt([]byte(payload), jwe.WithKey(jwa.RSA_OAEP, pubkey), jwe.WithContentEncryption(\"A128CBC-HS256\"), jwe.WithCompress(jwa.Deflate))\nrequire.NoError(t, err, `jwe.Encrypt should succeed`)\n_, err = jwe.Decrypt(encrypted, jwe.WithKey(jwa.RSA_OAEP, privkey)) // Will be allocating large amounts of memory\nrequire.Error(t, err, `jwe.Decrypt should fail`)\n```\n\n###  References\n\n[1] [CVE-2024-21319](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/security/advisories/GHSA-8g9c-28fc-mcx2)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/lestrrat-go/jwx/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.0.21"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/lestrrat-go/jwx"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.2.29"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/lestrrat-go/jwx/security/advisories/GHSA-hj3v-m684-v259"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-28122"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lestrrat-go/jwx/commit/d01027d74c7376d66037a10f4f64af9af26a7e34"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lestrrat-go/jwx/commit/d43f2ceb7f0c13714dfe8854d6439766e86faa76"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/lestrrat-go/jwx"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lestrrat-go/jwx/releases/tag/v1.2.29"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lestrrat-go/jwx/releases/tag/v2.0.21"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-400" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-03-08T15:06:53Z",
    "nvd_published_at" : "2024-03-09T01:15:06Z"
  }
}