VAITP Dataset

← Back to the dataset

CVE-2026-63470

Triple‑quote injection in generated FastAPI handlers allows code execution.

  • 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 Operation.summary into a generated route-handler docstring as a triple-double-quoted string without escaping embedded triple quotes. An attacker-controlled or attacker-influenced operation summary can close the docstring and inject a valid Python expression statement into the handler body. Syntax-breaking input only causes generation to fail, but syntactically valid generated code executes with the server process's privileges when the affected route handler is called. This call-time route-handler docstring sink is distinct from the project's separate import-time route-path and additional-response-key sinks. This issue is fixed in version 0.8.1.

CVSS base score
9.3
Published
2026-11-03
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Missing Check
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, APIRouter

app = FastAPI()
router = APIRouter()


def generate_handler(summary: str):
    # VULNERABLE: embeds unescaped summary in triple‑quoted docstring
    handler_code = f'''
def handler():
    """{summary}"""
    return {"message": "ok"}
'''
    exec_locals = {}
    exec(handler_code, {}, exec_locals)
    return exec_locals['handler']


# Simulate generation from an OpenAPI operation with a malicious summary
malicious_summary = 'Normal summary"""\\nimport os; os.system("rm -rf /")\\n"""'
router.add_api_route("/vuln", generate_handler(malicious_summary), methods=["GET"])
app.include_router(router)

Patched code sample

from fastapi import FastAPI, APIRouter

app = FastAPI()
router = APIRouter()


def generate_handler(summary: str):
    # FIX: escape triple quotes before embedding in docstring
    safe_summary = summary.replace('"""', '\\"""')
    handler_code = f'''
def handler():
    """{safe_summary}"""
    return {"message": "ok"}
'''
    exec_locals = {}
    exec(handler_code, {}, exec_locals)
    return exec_locals['handler']


# Generate handler with the same summary; injection is now neutralized
malicious_summary = 'Normal summary"""\\nimport os; os.system("rm -rf /")\\n"""'
router.add_api_route("/vuln", generate_handler(malicious_summary), methods=["GET"])
app.include_router(router)

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:cve202663470,
  title        = {{Triple‑quote injection in generated FastAPI handlers allows code execution.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-63470},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-63470/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.