fastapi-code-generator: Arbitrary code execution via OpenAPI spec status-code injection (CVE-2026-63469)
The fastapi-code-generator package fails to sanitize status-code keys in OpenAPI specifications, allowing attackers to inject and execute arbitrary Python code during the generation or subsequent import of a FastAPI application.
CVE search metadata
CVE search record: CVE-2026-63469. EPSS: 0.31%. KEV: no. Product: fastapi-code-generator (< 0.8.1). Brief: fastapi-code-generator: Arbitrary code execution via OpenAPI spec status-code injection (CVE-2026-63469). Brief link: https://feed.craftedsignal.io/briefs/2026-11-fastapi-code-generator-rce-538e69ce/
Triage facts
Revision 1- Applicability
- fastapi-code-generator (< 0.8.1)
- Evidence
- Unknown
- Severity
- Critical
- Action
- Immediate escalation
- Sources
- 1 public source
- Freshness
- Revision 1Nov 9, 22:11 UTC
- Vulnerabilities
- 1 CVE
- Source quality
- A1Likely
fastapi-code-generator (versions prior to 0.8.1) is vulnerable to remote code execution (RCE) via improper neutralization of special elements in the status-code key of the responses dictionary. When an OpenAPI specification contains a crafted status-code string (e.g., '404' + __import__("os").system('cmd') + 'x'), the generator emits this into the route decorator. Because the generated code is evaluated when the FastAPI application is imported by the ASGI server, the injected expression executes immediately.
Attack Chain
- Attacker creates a malicious OpenAPI specification containing an operation with a multi-response status-code key.
- Attacker embeds a Python payload within the status-code string using single quotes to break the string literal context.
- Attacker triggers the victim to run fastapi-code-generator using the malicious specification.
- The tool generates a
main.pyfile containing the unsanitized, injected payload within a route decorator. - The victim deploys the generated application to an ASGI server environment.
- The ASGI server imports
main.pyat application startup, triggering the execution of the injected Python code.
Impact
Successful exploitation allows for arbitrary code execution with the privileges of the process running the FastAPI application. This poses a critical risk in environments where generated code is automatically processed or deployed via CI/CD pipelines.
Recommendation
- Upgrade fastapi-code-generator to version 0.8.1 or later immediately to incorporate proper status-code key escaping.
- Audit existing codebases generated by older versions of the tool for suspicious content within route decorators, specifically within the
responses={...}dictionary of API endpoints. - Implement strict input validation on OpenAPI specifications processed by automated generation pipelines to ensure status-code keys conform to numeric or expected patterns.
Immediate actions
Upgrade fastapi-code-generator to 0.8.1 or later
Threat Hunt
Search generated Python source code for suspicious string concatenation or function calls within decorator parameters
Data: Code repository source files, Regex scan for @app.* decorator with responses parameter containing string concatenation characters (+, __import__, eval, exec)
Mitigations
Upgrade fastapi-code-generator to 0.8.1
CVE-2026-63469