CVE-2025-54365
Python vulnerability analysis and mitigation

Overview

CVE-2025-54365 is a regex bypass vulnerability in fastapi-guard, a security middleware library for FastAPI applications. The flaw exists specifically in version 3.0.1, where a prior patch intended to mitigate ReDoS (Regular Expression Denial of Service) by introducing bounded quantifiers (e.g., {0,100}) inadvertently created a bypass condition: inputs with <script> tag attributes exceeding 100 characters evade detection, allowing most regex-based security patterns to be circumvented. The vulnerability was published on July 23, 2025, and affects only fastapi-guard == 3.0.1 (pip package). It carries a CVSS v4 base score of 7.8 (High) and a CVSS v3.1 base score of 7.5 (High) (Github Advisory, Feedly).

Technical details

The root cause is classified under CWE-20 (Improper Input Validation), CWE-185 (Incorrect Regular Expression), and CWE-1333 (Inefficient Regular Expression Complexity). In version 3.0.1, the ReDoS mitigation replaced unbounded quantifiers (e.g., [^<]*) with bounded ones (e.g., [^<]{0,100}), but this approach fails when the input string — particularly the attributes portion of a <script> tag — exceeds the imposed character limit, causing the pattern to not match and thus silently pass the security check. This affects patterns across multiple attack categories in guard/handlers/suspatterns_handler.py, including XSS, SQL injection, command injection, LDAP injection, SSRF, and template injection detection. The attack vector is network-based, requires no authentication or user interaction, and can be triggered by crafting HTTP request bodies, query parameters, headers, or paths with payloads exceeding the bounded quantifier thresholds (Github Advisory, Patch Commit).

Impact

Successful exploitation allows an attacker to bypass the penetration detection middleware entirely, enabling injection attacks — including XSS, SQL injection, command injection, SSRF, and template injection — against the underlying FastAPI application that relies on fastapi-guard for protection. The primary impact is high availability risk (potential for ReDoS via catastrophic backtracking if unbounded patterns are re-introduced) and low-to-moderate integrity risk through injection payloads that bypass security filters. Confidentiality is not directly impacted by the bypass itself, but downstream injection attacks enabled by the bypass could expose sensitive data or allow unauthorized actions (Github Advisory).

Exploitability

A proof-of-concept (PoC) exploit is publicly available in the GitHub security advisory, demonstrating the bypass using a crafted HTTP POST request with a <script> tag whose attributes exceed 100 characters. There is no evidence of in-the-wild exploitation at this time, and no threat actor attribution has been reported. The EPSS score is approximately 0.094% (0.000940), indicating a low but non-zero probability of exploitation in the near term. The vulnerability is not listed in the CISA Known Exploited Vulnerabilities (KEV) catalog (Github Advisory, Feedly).

Exploitation steps

  1. Identify target: Locate a FastAPI application using fastapi-guard version 3.0.1 as middleware with penetration detection enabled (e.g., enable_penetration_detection=True in SecurityConfig).
  2. Clone the repository for reference (optional): Run git clone https://github.com/rennf93/fastapi-guard and navigate to the examples/ directory to understand the middleware configuration.
  3. Craft a bypass payload: Construct a <script> tag payload where the attributes portion exceeds 100 characters, causing the bounded quantifier {0,100} in the regex to fail to match. For example: <script aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>alert(1);</script>.
  4. Send the crafted request: Submit an HTTP POST request with the bypass payload embedded in the JSON body:
import requests
URL = "http://target-app:8000/"
bypassed_payload = {"suspicious": "<script " + "a"*101 + ">alert(1);"}
response = requests.post(url=URL, json=bypassed_payload)
print(f"[+] Response: {response.text}")
  1. Confirm bypass: A non-blocked response (e.g., HTTP 200) confirms the security filter was bypassed, whereas a standard XSS payload without the long attribute string would be blocked.
  2. Escalate: Use the confirmed bypass to deliver actual attack payloads (XSS, SQL injection, command injection, etc.) to the underlying application endpoints (Github Advisory).

Indicators of compromise

  • Network: HTTP POST (or other method) requests to FastAPI endpoints containing <script> tags with attribute strings exceeding 100 characters; requests with SQL keywords (SELECT, UNION, FROM) or command injection patterns in body/query params that are not blocked by the middleware.
  • Logs: Application logs showing requests with long <script> attribute strings that were not flagged by detect_penetration_attempt(); absence of expected WARNING - Regex timeout exceeded or penetration detection log entries for suspicious inputs.
  • Application Behavior: Unexpected application responses (e.g., HTTP 200) to requests containing obvious injection payloads padded with long attribute strings; downstream application errors consistent with XSS or SQL injection reaching the application layer.
  • Process: Unusual child processes or database errors originating from the FastAPI application process following receipt of crafted requests (Github Advisory).

Mitigation and workarounds

Upgrade fastapi-guard to version 3.0.2 immediately, which resolves the bypass by reverting to unbounded quantifiers and instead implementing a configurable regex execution timeout (regex_timeout) via ThreadPoolExecutor to prevent ReDoS without introducing bypassable length limits. The new regex_timeout parameter (default: 2.0 seconds, range: 0.1–30.0 seconds) can be set in SecurityConfig. No configuration-based workaround exists for version 3.0.1 — upgrading is the only effective remediation (Github Advisory, Patch Commit).

from guard.models import SecurityConfig
config = SecurityConfig(
    enable_penetration_detection=True,
    regex_timeout=2.0  # New in v3.0.2
)

Community reactions

The vulnerability was reported by researcher dhki and remediated by the library maintainer rennf93, who published the advisory and patch on July 23, 2025. The fix was noted in the changelog as an "IMPORTANT" security enhancement. No significant broader media coverage or notable community commentary beyond the GitHub advisory has been identified (Github Advisory).

Additional resources


SourceThis report was generated using AI

Related Python vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

CVE-2026-61539CRITICAL10
  • Python logoPython
  • xinference
NoYesAug 21, 2026
CVE-2026-49360HIGH7.8
  • Python logoPython
  • recce
NoYesAug 21, 2026
CVE-2026-68508HIGH7.8
  • Python logoPython
  • hydra-core
NoYesAug 21, 2026
CVE-2026-54457HIGH7.7
  • Python logoPython
  • tensorzero
NoYesAug 21, 2026
CVE-2026-43980MEDIUM6.3
  • Python logoPython
  • malla
NoNoAug 21, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management