VAITP Dataset

← Back to the dataset

CVE-2026-63469

Code injection via unescaped response key in FastAPI generator (pre‑0.8.1).

  • 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 additional response status-code key into the generated responses={…} route-decorator dictionary as a single-quoted Python string without escaping embedded quotes. A multi-response OpenAPI operation with an attacker-controlled or attacker-influenced second non-primary response key can close the dictionary-key literal and inject a valid Python expression. 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 its decorator arguments are evaluated. This additional-response-key sink is distinct from the project's separate route-path and operation-summary 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
Build/Package/Merge
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

import json
from fastapi import FastAPI, APIRouter

app = FastAPI()
router = APIRouter()

def generate_responses(operation: dict) -> str:
    # VULNERABLE: unsanitized insertion of response key string
    extra_key = operation.get("extra_response_key", "")
    # The extra_key may contain quotes that close the string literal.
    return f"{{'200': {{'description': 'OK'}}, '{extra_key}': {{'description': 'Injected'}}}}"

# Simulated generated route
@router.get("/items", responses=eval(generate_responses({
    "extra_response_key": "400'); __import__('os').system('echo compromised') #"
})))
def read_items():
    return {"msg": "safe"}

app.include_router(router)

Patched code sample

import json
from fastapi import FastAPI, APIRouter

app = FastAPI()
router = APIRouter()

def generate_responses(operation: dict) -> dict:
    # FIX: safely construct the responses dict without string injection
    extra_key = operation.get("extra_response_key")
    base = {"200": {"description": "OK"}}
    if extra_key:
        # Ensure the key is a plain string and cannot inject code
        base[str(extra_key)] = {"description": "Injected"}
    return base

# Simulated generated route
@router.get("/items", responses=generate_responses({
    "extra_response_key": "400'); __import__('os').system('echo compromised') #"
}))
def read_items():
    return {"msg": "safe"}

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:cve202663469,
  title        = {{Code injection via unescaped response key in FastAPI generator (pre‑0.8.1).}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-63469},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-63469/}}
}

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.