CVE-2024-37298: Github.com/gorilla/schema Potential Memory Exhaustion Attack Due Vulnerability

HIGH
Advisory Identifier: GHSA-3669-72x9-r9p3
CVSS 7.5
CWE-770
Published
Advisory Summary

CVE-2024-37298 is a HIGH (CVSS 7.5) potential memory exhaustion attack due vulnerability (CWE-770: Allocation of Resources Without Limits or Throttling) affecting Github.com/gorilla/schema libraries in the Go ecosystem. The issue involves potential memory exhaustion attack due to sparse slice deserialization. Remediation is available by upgrading affected packages to version 1.4.1.

CVE-2024-37298 at a Glance

CVE Identifier CVE-2024-37298
GHSA Identifier GHSA-3669-72x9-r9p3
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-770: Allocation of Resources Without Limits or Throttling
Affected Product Github.com/gorilla/schema
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:N/I:N/A:H).

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

How to Fix CVE-2024-37298

To remediate this vulnerability, upgrade all affected Github.com/gorilla/schema 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/gorilla/schema fixed: 1.4.1
Upgrade github.com/gorilla/schema to 1.4.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/gorilla/schema

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-37298, inspect your project dependencies for Github.com/gorilla/schema:

inspect dependencies for github.com/gorilla/schema

Analyze the terminal output to locate any version of Github.com/gorilla/schema in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.4.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-770: Allocation of Resources Without Limits or Throttling, where the product allocates a reusable resource or group of resources on behalf of an actor without imposing any intended restrictions on the size or number of resources that can be allocated. In Github.com/gorilla/schema, 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

### Details Running `schema.Decoder.Decode()` on a struct that has a field of type `[]struct{...}` opens it up to malicious attacks regarding memory allocations, taking advantage of the sparse slice functionality. For instance, in the Proof of Concept written below, someone can specify to set a field of the billionth element and it will allocate all other elements before it in the slice. In the local environment environment for my project, I was able to call an endpoint like `/innocent_endpoint?arr.10000000.X=1` and freeze my system from the memory allocation while parsing `r.Form`. I think [this line](https://github.com/gorilla/schema/blob/main/decoder.go#L223) is responsible for allocating the slice, although I haven't tested to make sure, so it's just an educated guess. ### Proof of Concept The following proof of concept works on both v1.2.0 and v1.2.1. I have not tested earlier versions. ```go package main import ( "fmt" "github.com/gorilla/schema" ) func main() { dec := schema.NewDecoder() var result struct { Arr []struct{ Val int } } if err := dec.Decode(&result, map[string][]string{"arr.1000000000.Val": {"1"}}); err != nil { panic(err) } fmt.Printf("%#+v\n", result) } ``` ### Impact Any use of `schema.Decoder.Decode()` on a struct with arrays of other structs could be vulnerable to this memory exhaustion vulnerability. There seems to be no possible solution that a developer using this library can do to disable this behaviour without fixing it in this project, so all uses of Decode that fall under this umbrella are affected. A fix that doesn't require a major change may also be harder to find, since it could break compatibility with some other intended use-cases.

CVE-2024-37298 Affected Github.com/gorilla/schema Versions

1 component(s)
Fixed Versions:
1.4.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/gorilla/schema
Go
< 1.4.1
1.4.1

References

Frequently Asked Questions

What is CVE-2024-37298?
CVE-2024-37298 is a security vulnerability in Github.com/gorilla/schema involving Potential memory exhaustion attack due to sparse slice deserialization under CWE-770: Allocation of Resources Without Limits or Throttling.
Which Github.com/gorilla/schema versions are affected?
Affected versions include releases prior to 1.4.1 across affected packages: github.com/gorilla/schema.
What version fixes CVE-2024-37298?
Upgrading to 1.4.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/gorilla/schema affected?
Yes, github.com/gorilla/schema is affected in releases prior to 1.4.1. Upgrade your dependency to 1.4.1 or later.
What is the CVSS score of CVE-2024-37298?
CVE-2024-37298 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:N/I:N/A:H.
What CWE is associated with CVE-2024-37298?
CVE-2024-37298 is classified under CWE-770: Allocation of Resources Without Limits or Throttling (The product allocates a reusable resource or group of resources on behalf of an actor without imposing any intended restrictions on the size or number of resources that can be allocated.).
How can I check Go dependencies for CVE-2024-37298?
Run the dependency tree command: 'inspect dependencies for github.com/gorilla/schema'. 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-3669-72x9-r9p3",
  "modified" : "2024-07-05T21:29:07Z",
  "published" : "2024-07-01T20:35:12Z",
  "aliases" : [ "CVE-2024-37298" ],
  "summary" : "Potential memory exhaustion attack due to sparse slice deserialization",
  "details" : "### Details\n\nRunning `schema.Decoder.Decode()` on a struct that has a field of type `[]struct{...}` opens it up to malicious attacks regarding memory allocations, taking advantage of the sparse slice functionality. For instance, in the Proof of Concept written below, someone can specify to set a field of the billionth element and it will allocate all other elements before it in the slice. \n\nIn the local environment environment for my project, I was able to call an endpoint like `/innocent_endpoint?arr.10000000.X=1` and freeze my system from the memory allocation while parsing `r.Form`. I think [this line](https://github.com/gorilla/schema/blob/main/decoder.go#L223) is responsible for allocating the slice, although I haven't tested to make sure, so it's just an educated guess.\n\n### Proof of Concept\n\nThe following proof of concept works on both v1.2.0 and v1.2.1. I have not tested earlier versions.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/gorilla/schema\"\n)\n\nfunc main() {\n\tdec := schema.NewDecoder()\n\tvar result struct {\n\t\tArr []struct{ Val int }\n\t}\n\tif err := dec.Decode(&result, map[string][]string{\"arr.1000000000.Val\": {\"1\"}}); err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"%#+v\\n\", result)\n}\n\n```\n\n### Impact\n\nAny use of `schema.Decoder.Decode()` on a struct with arrays of other structs could be vulnerable to this memory exhaustion vulnerability. There seems to be no possible solution that a developer using this library can do to disable this behaviour without fixing it in this project, so all uses of Decode that fall under this umbrella are affected. A fix that doesn't require a major change may also be harder to find, since it could break compatibility with some other intended use-cases.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/gorilla/schema"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.4.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/gorilla/schema/security/advisories/GHSA-3669-72x9-r9p3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-37298"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/gorilla/schema/commit/cd59f2f12cbdfa9c06aa63e425d1fe4a806967ff"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/gorilla/schema"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/gorilla/schema/blob/main/decoder.go#L223"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-770" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-01T20:35:12Z",
    "nvd_published_at" : "2024-07-01T19:15:04Z"
  }
}