Miggo Logo

CVE-2025-59152: Litestar X-Forwarded-For Header Spoofing Vulnerability Enables Rate Limit Evasion

7.5

CVSS Score
3.1

Basic Information

EPSS Score
-
Published
10/6/2025
Updated
10/6/2025
KEV Status
No
Technology
TechnologyPython

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Package NameEcosystemVulnerable VersionsFirst Patched Version
litestarpip= 2.17.02.18.0

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability lies in Litestar's RateLimitMiddleware, which improperly trusted the X-Forwarded-For header to identify clients for rate-limiting purposes. The root cause is located in the cache_key_from_request method within the RateLimitMiddleware class. Before the patch, this method would read the X-Forwarded-For or X-Real-IP headers and use their values to generate a cache key. As detailed in the commit 42a89e043e50b515f8548a93954fe143f63cf9fb, the vulnerable line was identifier = request.headers.get("X-Forwarded-For") or request.headers.get("X-Real-IP") or host. An attacker could exploit this by sending a different IP in the X-Forwarded-For header with each request, effectively creating a new rate-limit bucket for each request and never hitting the limit. This allows for bypassing rate limits intended to protect against brute-force attacks, API abuse, and resource exhaustion. The patch remediates this by removing the direct header access and introducing a configurable identifier_for_request callable, which defaults to a new safe function get_remote_address that only uses the trusted socket IP (request.client.host).

Vulnerable functions

RateLimitMiddleware.cache_key_from_request
litestar/middleware/rate_limit.py
This function was responsible for generating a unique key for each client to track request rates. The vulnerability existed because this function used the 'X-Forwarded-For' or 'X-Real-IP' headers to create this key. These headers can be arbitrarily set by a client. By sending different IP addresses in this header for each request, an attacker could bypass the rate limit entirely, as each request would be treated as coming from a new, unique user.

WAF Protection Rules

WAF Rule

W*il* t*stin* Lit*st*r's R*t*LimitMi**l*w*r*, it w*s *is*ov*r** t**t r*t* limits **n ** *ompl*t*ly *yp*ss** *y m*nipul*tin* t** X-*orw*r***-*or *****r. T*is r*n**rs IP-**s** r*t* limitin* in*****tiv* ***inst **t*rmin** *tt**k*rs. ## T** Pro*l*m Lit

Reasoning

T** vuln*r**ility li*s in Lit*st*r's `R*t*LimitMi**l*w*r*`, w*i** improp*rly trust** t** `X-*orw*r***-*or` *****r to i**nti*y *li*nts *or r*t*-limitin* purpos*s. T** root **us* is lo**t** in t** `*****_k*y_*rom_r*qu*st` m*t*o* wit*in t** `R*t*LimitMi