Critical · 9.3 Critical vulnerabilities CVE-2026-63471
fastapi-code-generator: Code Injection via Unescaped OpenAPI Route Paths (CVE-2026-63471)
fastapi-code-generator versions before 0.8.1 fail to escape OpenAPI path strings when building @app.get(...) route decorators, allowing a crafted OpenAPI path to inject Python code that runs when the generated module is imported.
By PatchBriefing · ·
Produced automatically from official sources with the help of AI. How we work →
AI summary
fastapi-code-generator is a tool that builds FastAPI applications automatically from OpenAPI specification files. A vulnerability tracked as CVE-2026-63471 affects how the tool generates route decorators from OpenAPI path values. In affected versions, an OpenAPI path can be crafted to break out of the generated string and inject arbitrary Python code, which executes as soon as the generated application module is imported.
What happened
fastapi-code-generator takes an OpenAPI specification and generates a FastAPI application, including Python route handlers decorated with statements such as @app.get('...'). Prior to version 0.8.1, the tool inserted the OpenAPI path value directly into this decorator as a single-quoted string without escaping embedded quote characters. If an OpenAPI path contains a quote character followed by valid Python syntax, that syntax can close the intended string early and be interpreted as part of the decorator expression rather than as literal text.
Technical cause
The root cause is missing input sanitization (CWE-94, improper control of code generation) at the point where an OpenAPI path is embedded into a generated @app.get(...) decorator string. Because the value is inserted unescaped, an attacker-controlled or attacker-influenced path can terminate the string literal and append a syntactically valid Python expression. If the resulting generated file is syntactically invalid Python, code generation simply fails; but if the injected expression is valid, it becomes part of the generated source file and executes with the privileges of whatever process imports that module, whether that is the running application or a CI/build pipeline. This OpenAPI path sink is separate from two other known injection points in the same project: the operation-summary docstring sink and the additional-response-key sink.
Why it matters
Any workflow that generates a FastAPI application from an OpenAPI document where the path values are not fully trusted is at risk. This includes scenarios where OpenAPI specifications are produced or modified by third parties, pulled from external sources, or processed in automated pipelines without strict validation. Because exploitation occurs at import time rather than requiring a running, exposed service to be directly reachable, the impact can extend to build and CI systems that generate and import the code as part of their normal process.
Who is affected
Organizations and developers using fastapi-code-generator in versions before 0.8.1 to generate FastAPI applications from OpenAPI specifications are affected, particularly where the OpenAPI input is not guaranteed to come from a fully trusted source.
Affected versions
Versions of fastapi-code-generator before 0.8.1 are affected. The vulnerability is fixed in version 0.8.1.
Fixes and mitigation
The issue is fixed in fastapi-code-generator version 0.8.1. Users should update to version 0.8.1 or later. Until an update is applied, treat any OpenAPI specification from an untrusted or only partially trusted source as potentially hazardous input, since path values in such a document can be used to inject code into generated route decorators.
Recommended action
Update fastapi-code-generator to version 0.8.1 or later. Audit existing OpenAPI specifications used to generate FastAPI applications for unexpected or suspicious path values, especially specifications that originate from external or automated sources. Review CI and build pipelines that generate and subsequently import fastapi-code-generator output to ensure generated code is treated with the same scrutiny as any other build artifact derived from untrusted input.
PatchBriefing score
9.3 / 10 · Critical
Official CVSS: 9.3
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
EPSS 0.0054 (39 percentile)
Why this score
The PatchBriefing score equals the official CVSS score; when this article covers several vulnerabilities, the highest one. Signals such as known exploitation and EPSS are listed separately and do not change the score.
Affected versions
Reported fixes
The issue is fixed in fastapi-code-generator version 0.8.1. Users should update to version 0.8.1 or later. Until an update is applied, treat any OpenAPI specification from an untrusted or only partially trusted source as potentially hazardous input, since path values in such a document can be used to inject code into generated route decorators.
How this was built
2 source records were collected, matched and used to prepare the report above.
-
NVD (NIST) database
-
CVE.org database
Revision history
- Published
- Generated
- Published
- Generated