CVE-2024-39305
Executive Summary
CVE-2024-39305 is a use-after-free vulnerability in Envoy, a cloud-native edge and service proxy. The flaw occurs when a route hash policy is configured with cookie attributes. During configuration parsing, memory allocated for holding attribute values is freed prematurely. When a request is processed, Envoy attempts to copy content from this de-allocated memory into the request cookie header, leading to potential information disclosure (arbitrary memory content sent to upstream services) or abnormal process termination (denial of service). The vulnerability has a CVSS score of 6.5 (Medium) and affects Envoy versions prior to 1.30.4, 1.29.7, 1.28.5, and 1.27.7. Patches are available, and a workaround is to avoid using cookie attributes in route action hash policy.
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
Envoy is a critical component in many cloud-native environments, often deployed as a sidecar proxy in service meshes (e.g., Istio). A use-after-free vulnerability in Envoy can compromise the confidentiality and availability of the entire service mesh. Organizations using Envoy should prioritize patching to prevent potential data leaks or service disruptions.
CVSS Breakdown & Threat Level
- CVSS Score: 6.5 (Medium)
- Attack Vector (AV): Network (N)
- Attack Complexity (AC): Low (L)
- Privileges Required (PR): None (N)
- User Interaction (UI): None (N)
- Scope (S): Unchanged (U)
- Confidentiality (C): Low (L)
- Integrity (I): None (N)
- Availability (A): Low (L)
The vulnerability is remotely exploitable without authentication, but it requires a specific configuration (cookie attributes in route hash policy). The impact is limited to information disclosure and potential denial of service.
Deep Dive & Mechanics
The vulnerability resides in Envoy's route hash policy implementation, specifically when cookie attributes are used. During configuration parsing, Envoy allocates memory to store attribute values (e.g., cookie name, path, domain). However, after parsing is complete, this memory is freed prematurely. When a subsequent request matches the route, Envoy attempts to read from the freed memory to construct the cookie header for upstream forwarding. This results in a use-after-free condition.
The freed memory may contain sensitive data from other parts of Envoy's heap, or it may have been reallocated for other purposes. This can lead to:
- Information Disclosure: Arbitrary memory contents (including secrets, tokens, or other sensitive data) are sent to upstream services in the cookie header.
- Denial of Service: If the freed memory is unmapped or corrupted, Envoy may crash (abnormal process termination).
The vulnerability is triggered only when a route hash policy is configured with cookie attributes. Without this specific configuration, the vulnerable code path is not executed.
Vulnerable vs. Patched Code
Vulnerable Code (simplified):
// During configuration parsing
std::string* cookie_attributes = new std::string(config.attributes());
// ... parse and use cookie_attributes ...
delete cookie_attributes; // Memory freed prematurely
// During request processing
Http::HeaderMap& headers = request.headers();
headers.addReferenceKey(Http::Headers::get().Cookie, *cookie_attributes); // Use-after-free
Patched Code (simplified):
// During configuration parsing
std::string cookie_attributes = config.attributes(); // Stored as value, not pointer
// ... parse and use cookie_attributes ...
// During request processing
Http::HeaderMap& headers = request.headers();
headers.addReferenceKey(Http::Headers::get().Cookie, cookie_attributes); // Safe access
The fix involves storing the cookie attributes as a value (not a dynamically allocated pointer) or extending their lifetime until after request processing. The patch ensures that the memory remains valid when accessed.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- An Envoy instance running a vulnerable version (e.g., 1.27.6).
- A route configuration that includes a hash policy with cookie attributes.
Exploitation Steps:
- Identify an Envoy proxy with a route that uses cookie-based hash policy.
- Send a crafted request that triggers the vulnerable code path.
- Observe the response or upstream behavior to extract leaked memory.
Example Request:
GET / HTTP/1.1
Host: vulnerable-envoy.example.com
Cookie: session=abc123
Expected Outcome:
- The upstream service may receive a cookie header containing leaked memory data.
- Envoy may crash, causing a denial of service.
Note: No public exploit code is available for this vulnerability.
Blue Team (Detection & Defense)
Detection:
- Monitor Envoy logs for crashes or unexpected behavior.
- Use memory analysis tools to detect use-after-free patterns.
- Implement network monitoring for anomalous cookie headers.
Defense:
- Apply the patch immediately.
- As a workaround, remove cookie attributes from route hash policy configurations.
- Restrict network access to Envoy's management interface.
Indicators of Compromise (IOCs)
- Network: Upstream services receiving cookie headers with unexpected or binary data.
- Logs: Envoy crash logs indicating segmentation faults or memory corruption.
- Memory: Heap dumps showing freed memory being accessed.
Example IOC (Log Entry):
[2024-06-01 12:34:56.789][12345][critical][assert] assert failure: use-after-free in route_hash_policy.cc:42
Detection Engineering
YARA Rule
rule CVE_2024_39305_Envoy_UseAfterFree {
meta:
description = "Detects Envoy binary with use-after-free vulnerability in route hash policy"
author = "Valters IT"
date = "2024-06-01"
reference = "CVE-2024-39305"
strings:
$s1 = "cookie_attributes" ascii wide nocase
$s2 = "delete" ascii wide nocase
$s3 = "addReferenceKey" ascii wide nocase
condition:
all of them
}
Sigma Rule
title: CVE-2024-39305 Envoy Use-After-Free Detection
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects potential exploitation of CVE-2024-39305 in Envoy logs
author: Valters IT
date: 2024-06-01
logsource:
category: application
product: envoy
detection:
selection:
- "assert failure: use-after-free"
- "segmentation fault"
- "memory corruption"
condition: selection
falsepositives:
- Legitimate crashes due to other bugs
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-39305 Envoy Use-After-Free Exploit Attempt"; flow:to_server; content:"Cookie"; http_header; pcre:"/Cookie:\s*[^\r\n]{100,}/Ri"; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Upgrade Envoy to versions v1.30.4, v1.29.7, v1.28.5, or v1.27.7.
- If upgrading is not possible, remove cookie attributes from all route hash policy configurations.
Long-term Measures:
- Implement memory safety checks in CI/CD pipelines.
- Regularly update Envoy to the latest stable version.
- Monitor Envoy security advisories.
Workaround:
- Do not use cookie attributes in route action hash policy.
Valters IT