CVE-2026-63471
Code injection via unescaped OpenAPI path in generated @app.get decorator.
- CVSS 9.3
- CWE-94
- Input Validation and Sanitization
- Remote
fastapi-code-generator creates FastAPI applications from OpenAPI files. Prior to 0.8.1, the generator inserts an OpenAPI path into a generated @app.get(…) route decorator as a single-quoted generated route string without escaping embedded quotes. An attacker-controlled or attacker-influenced OpenAPI path can close the string and inject a valid Python expression into the decorator argument. Syntax-breaking input only causes generation to fail, but syntactically valid generated code executes with the application's or CI process's privileges when the generated module is imported and the decorator is evaluated. This OpenAPI path sink is distinct from the project's separate operation-summary docstring and additional-response-key sinks. This issue is fixed in version 0.8.1.
- CWE
- CWE-94
- CVSS base score
- 9.3
- Published
- 2026-11-03
- OWASP
- A03 Injection
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Interface
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- fastapi-code-generator
- Fixed by upgrading
- Yes
Solution
Upgrade fastapi-code-generator to version 0.8.1 or later.
Vulnerable code sample
from fastapi import FastAPI
app = FastAPI()
# VULNERABLE: unsanitized OpenAPI path used directly in decorator
@app.get('/' + __import__("os").system("echo vulnerable") + '/items')
def list_items():
return {"items": []}Patched code sample
from fastapi import FastAPI
app = FastAPI()
# FIX: use a literal path string, avoiding code execution
@app.get('/items')
def list_items():
return {"items": []}Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Fix generated Python literal escaping (koxudaxi/fastapi-code-generator)
fastapi_code_generator/parser.py,fastapi_code_generator/parser.py · Operation.function_name,fastapi_code_generator/parser.py · Operation.root_path,fastapi_code_generator/parser.py · Operation.snake_case_path,fastapi_code_generator/parser.py · UsefulStr.validate,fastapi_code_generator/prompt_data.py
Cite this entry
@misc{vaitp:cve202663471,
title = {{Code injection via unescaped OpenAPI path in generated @app.get decorator.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-63471},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-63471/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
