Asymmetric denial of service - ReDoS In litestar
Description
Litestar's AllowedHosts has a validation bypass due to unescaped regex metacharacters in configured host patterns
Summary
AllowedHosts host validation can be bypassed because configured host patterns are turned into regular expressions without escaping regex metacharacters (notably .). A configured allowlist entry like example.com can match exampleXcom
Details
In litestar.middleware.allowed_hosts, allowlist entries are compiled into regex patterns in a way that allows regex metacharacters to retain special meaning (e.g., . matches any character). This enables a bypass where an attacker supplies a host that matches the regex but is not the intended literal hostname.
PoC
Server (poc_allowed_hosts_server.py)
from litestar import Litestar, get from litestar.middleware.allowed_hosts import AllowedHostsConfig @get("/") async def index() -> str: return "ok" config = AllowedHostsConfig(allowed_hosts=["example.com"])...
uvicorn poc_allowed_hosts_server:app --host 127.0.0.1 --port 8001
Client (poc_allowed_hosts_client.py)
import http.client def req(host_header: str) -> tuple[int, bytes]: c = http.client.HTTPConnection("127.0.0.1", 8001, timeout=3) c.request("GET", "/", headers={"Host": host_header}) r = c.getresponse() body = r.read() c.close()...
Expected (vulnerable behavior): Host: evil.com → 400 invalid host
Host: exampleXcom → 200 ok (bypass)
Impact
Type: security control bypass (host allowlist) Who is impacted: apps relying on AllowedHosts to prevent Host header attacks (cache poisoning, absolute URL construction abuse, password reset link poisoning, etc.). The downstream impact depends on app behavior, but the bypass defeats a core mitigation layer.
Mitigation
Update Impact
Minimal update. May introduce new vulnerabilities or breaking changes.
Ecosystem | Package | Affected version | Patched versions |
|---|---|---|---|
pypi | 2.20.0 |
Aliases
References