{"id":2721,"cve":"CVE-2026-63469","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-63469\/","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":9.3,"published":"2026-11-03","owasp":"A03 Injection","odc":"Build\/Package\/Merge","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Command Injection","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Code injection via unescaped response key in FastAPI generator (pre\u20110.8.1).","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-63469\/","description":"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.","solution":"Upgrade fastapi-code-generator to version\u202f0.8.1 or later.","affected_component":"fastapi-code-generator","fixed_by_upgrading":true,"vulnerable_code":"import json\nfrom fastapi import FastAPI, APIRouter\n\napp = FastAPI()\nrouter = APIRouter()\n\ndef generate_responses(operation: dict) -> str:\n    # VULNERABLE: unsanitized insertion of response key string\n    extra_key = operation.get(\"extra_response_key\", \"\")\n    # The extra_key may contain quotes that close the string literal.\n    return f\"{{'200': {{'description': 'OK'}}, '{extra_key}': {{'description': 'Injected'}}}}\"\n\n# Simulated generated route\n@router.get(\"\/items\", responses=eval(generate_responses({\n    \"extra_response_key\": \"400'); __import__('os').system('echo compromised') #\"\n})))\ndef read_items():\n    return {\"msg\": \"safe\"}\n\napp.include_router(router)\n","patched_code":"import json\nfrom fastapi import FastAPI, APIRouter\n\napp = FastAPI()\nrouter = APIRouter()\n\ndef generate_responses(operation: dict) -> dict:\n    # FIX: safely construct the responses dict without string injection\n    extra_key = operation.get(\"extra_response_key\")\n    base = {\"200\": {\"description\": \"OK\"}}\n    if extra_key:\n        # Ensure the key is a plain string and cannot inject code\n        base[str(extra_key)] = {\"description\": \"Injected\"}\n    return base\n\n# Simulated generated route\n@router.get(\"\/items\", responses=generate_responses({\n    \"extra_response_key\": \"400'); __import__('os').system('echo compromised') #\"\n}))\ndef read_items():\n    return {\"msg\": \"safe\"}\n\napp.include_router(router)\n","payload_needed":true,"payload":null,"payload_status":"model_refused","published_fix":[{"repository":"koxudaxi\/fastapi-code-generator","commit_url":"https:\/\/github.com\/koxudaxi\/fastapi-code-generator\/commit\/49301dbdb82170d7f50877419d994b05cb1fa2bc","commit_subject":"Fix generated Python literal escaping","units":[{"file":"fastapi_code_generator\/parser.py","function":null},{"file":"fastapi_code_generator\/parser.py","function":"Operation.function_name"},{"file":"fastapi_code_generator\/parser.py","function":"Operation.root_path"},{"file":"fastapi_code_generator\/parser.py","function":"Operation.snake_case_path"},{"file":"fastapi_code_generator\/parser.py","function":"UsefulStr.validate"},{"file":"fastapi_code_generator\/prompt_data.py","function":null}]}],"references":null}