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.
Published: 2026-11-03
Score: 9.3 Critical
EPSS: n/a
KEV: No
Impact: Import-time Remote Code Execution
Action: Immediate Patch
AI Analysis

Impact

A flaw in fastapi-code-generator allows an attacker to inject Python code through the "responses" dictionary of a route decorator. The generator places an attacker‑controlled second response key into the dictionary as a single‑quoted string without escaping internal quotes, so a syntactically valid payload can close the string literal and introduce a new expression. When the generated module is imported, the decorator arguments are evaluated, leading to execution of arbitrary code with the privileges of the application or the CI process. This vulnerability is a classic example of code injection (CWE‑94) compounded by improper escaping (CWE‑116), and it results in full remote code execution at import time.

Affected Systems

The impact is limited to installations of the koxudaxi:fastapi-code-generator package. Versions prior to 0.8.1 generate vulnerable code. Any project that uses the generator to produce FastAPI applications from OpenAPI definitions—and subsequently imports the generated module—falls within the affected scope.

Risk and Exploitability

The CVSS score of 9.3 marks the vulnerability as critical. EPSS data is not available, but the absence of a KEV listing does not diminish its severity. If an attacker can supply or influence the OpenAPI file that the generator processes, the injection can be performed remotely on a build or deployment environment. Exploitability is high because the vulnerability only requires the generation of code, which is usually done during build or documentation generation steps. Once the generated module is imported, the malicious code runs automatically, giving the attacker full control over the running process.

Generated by OpenCVE AI on November 3, 2026 at 20:38 UTC.

Remediation

No solution or workaround provided in the CVE record.

OpenCVE Recommended Actions

  • Upgrade fastapi-code-generator to version 0.8.1 or later, which removes the vulnerable response‑key handling.
  • If an upgrade cannot be performed immediately, modify the template or generator configuration to avoid using the "responses=" parameter for untrusted input, or manually sanitize the response keys in the generated code before import.
  • Run the code‑generation process in a controlled, least‑privilege environment such as a CI sandbox, and audit the generated artifacts for unintended code before deploying them to production.

Generated by OpenCVE AI on November 3, 2026 at 20:38 UTC.

Tracking

Sign in to view the affected projects.

Advisories

No advisories yet.

History

Tue, 03 Nov 2026 19:30:00 +0000

Type Values Removed Values Added
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.
Title fastapi-code-generator: Import-time RCE via response status-code key -> unescaped @app.get(..., responses={...}) dict
Weaknesses CWE-116
CWE-94
References
Metrics cvssV4_0

{'score': 9.3, 'vector': 'CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N'}


Subscriptions

No data.

cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-11-03T19:15:54.707Z

Reserved: 2026-07-16T21:37:45.769Z

Link: CVE-2026-63469

cve-icon Vulnrichment

No data.

cve-icon NVD

Status : Deferred

Published: 2026-11-03T20:18:15.420

Modified: 2026-11-03T20:31:38.783

Link: CVE-2026-63469

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-11-03T20:45:01Z

Weaknesses
  • CWE-116

    Improper Encoding or Escaping of Output

  • CWE-94

    Improper Control of Generation of Code ('Code Injection')