fastapi-code-generator CVE-2026-63469: OpenAPI spec input becomes code
A 9.3-rated flaw in fastapi-code-generator, not FastAPI itself, turns an untrusted OpenAPI spec into code that runs when the generated app or CI job imports main.py.
Automated engineering analysis by the Khalid Aboubakr Engineering Desk, from the primary sources listed below. Not reviewed by a person before publication. About the desk
Bottom line
fastapi-code-generator before 0.8.1 lets a crafted OpenAPI response status-code key inject Python that runs when the generated main.py is imported. A fix is available in 0.8.1, which also closes two sibling injection sinks. The real risk sits with teams that generate code from specs they do not fully control: upgrade, then regenerate and review existing output.
What happened
A code-injection flaw in the fastapi-code-generator package on PyPI is tracked as CVE-2026-63469 and GHSA-6xmv-cjr5-w3q8. The affected component is the generator, not the FastAPI framework. Versions below 0.8.1 are affected, and 0.8.1 is the first patched version.
The generator writes the status-code key of each additional response into the route decorator's responses={...} dict as a single-quoted string literal and does not escape it. That dict is only emitted when an operation has a second, non-primary response. Input that breaks the syntax only aborts generation, which is a denial of service. Syntactically valid injected input is written into the output and runs when main.py is imported. The ASGI server imports main.py at startup, so no request is needed. The injected code runs with the privileges of whichever application or CI process imports the generated module.
The advisory rates the issue Critical, describes that rating as an estimate, and gives a CVSS v4 vector with network attack vector, no privileges and no user interaction. NVD lists a base score of 9.3. The advisory says the issue is distinct from OpenAPI Generator's python-fastapi. NVD describes this sink as separate from two others in the same project: route path and operation summary. The 0.8.1 release fixes all three, under GHSA-6xmv-cjr5-w3q8, GHSA-p2mm-64f6-gmpp and GHSA-h667-4jj2-cgv4.
Why it matters
The precondition is an attacker-controlled or attacker-influenced OpenAPI spec containing a multi-response operation, which is then generated and imported or served. That precondition decides who is exposed, and the headline 9.3 does not show it.
- Teams generating only from specs they author and review have little practical exposure. Someone would already need write access to the spec.
- Teams generating from partner, vendor or third-party specs are the real target. Examples include integration hubs, API gateway scaffolding, and government or healthcare interoperability work, where specs arrive from other organisations. For them, the spec is now effectively code.
- CI pipelines are the most likely place the payload runs. A pipeline that generates the app and then imports it, for tests, OpenAPI schema export or an app-startup smoke test, executes the injected expression with whatever that job can reach: deploy credentials, registry tokens, cloud roles.
Nothing changes for a FastAPI service written by hand. Generic "FastAPI RCE" framing overstates the reach of this issue.
Engineering assessment
Our assessment: this is a supply-chain and build-pipeline issue, not a runtime web vulnerability. The CVSS vector (AV:N/PR:N/UI:N) describes the worst case, where an attacker can feed a spec into the pipeline. It does not describe a typical internet-facing FastAPI deployment. Even so, it should not be dismissed. The advisory rates attack complexity Low and describes a payload form that survives the generator's black/isort post-processing, so the attack is cheap where specs cross an organisational boundary, and it lands in CI, the environment that usually holds the most valuable credentials.
Three points the announcement underplays:
- Upgrading the generator does not clean existing output. Any
main.pyproduced by a vulnerable version from an untrusted spec still contains whatever was injected. The evidence does not say whether regeneration is required. The safe reading is that generated artifacts from untrusted specs need to be regenerated and diffed. - Three sinks in one release is a pattern. Route path, operation summary and response status-code key all failed the same way: spec strings were inserted into Python source without escaping. Version 0.8.1 fixes the three known fields. Whether other fields have the same flaw is not established by the evidence, so specs from untrusted sources should still be treated as untrusted input.
- Generated code is often committed and rarely read. Large generated diffs get rubber-stamped in review. A syntactically valid injected expression inside a decorator argument is easy to miss in a long diff.
Migration cost looks low. The 0.8.1 changelog lists only three escaping fixes, so compatibility risk looks low. The evidence does not show the diff, though, and the advisory's suggested fix also mentioned validating status-code keys, so check that regeneration still succeeds on unusual specs and expect regenerated output to differ textually.
For teams that already treat third-party specs as untrusted, this changes nothing in principle. For teams that treated specs as inert configuration, it should.
Is this you?
fastapi-code-generatorappears in any requirements file, lockfile, dev dependency group, CI image or developer tooling, at a version below 0.8.1.- You generate FastAPI apps from OpenAPI specs supplied by partners, vendors, customers or other teams, or from a shared repository many people can write to.
- Your CI generates code and then imports, tests or serves it in the same job.
- You have committed
main.pyfiles generated by a pre-0.8.1 version from a spec you did not author. - If you only use FastAPI directly and never run this generator, you are not affected by this CVE.
What to do
- Inventory. Find the generator across repos, CI images and developer environments:
pip show fastapi-code-generatorpip list | grep -i fastapi-code-generatorpoetry show fastapi-code-generatororuv pip show fastapi-code-generator, depending on tooling
- Upgrade to 0.8.1 wherever it appears, and pin it in lockfiles and CI images:
pip install --upgrade "fastapi-code-generator>=0.8.1". This closes all three escaping issues fixed in that release. - Regenerate and diff existing output for every app built from a spec you do not fully control. Review the
responses={...}dicts, route path strings and handler docstrings for anything that is not plain literal data. The vendor material does not explicitly require this step. - Confirm regeneration still works. Run the upgraded generator against your real specs, including unusual ones, and check that it completes before rolling the upgrade into every pipeline.
- Validate specs before generation. Not vendor guidance. Reject specs whose response keys are not numeric status codes or the expected pattern, and treat third-party specs as untrusted input.
- Reduce CI blast radius. Not vendor guidance. Run code generation from external specs in a job without deploy secrets or cloud credentials. Promote the generated output only after review.
- For technical leads: add code generators to your dependency-scanning scope. Build-time tools are often missed because they are not in production images.
Teams running integration platforms or enterprise API work that consume external specs should treat steps 3 and 6 as part of the fix, not optional hardening.
What we don't know yet
- Existing output. Whether
main.pyfiles already generated by a vulnerable version from an untrusted spec must be regenerated. The evidence does not say. - Older versions. The advisory reports verification on 0.8.0. The affected range covers everything below 0.8.1, and the evidence does not say how older versions were assessed.
- Other unescaped fields. Whether any spec fields beyond the three fixed in 0.8.1 are inserted without escaping.
- Disclosure timeline. The repository advisory and the 0.8.1 release are dated July 2026. The CVE and NVD records date from 3 November 2026, and the GitHub Advisory Database entry from 9 November 2026. The reason for the gap is not stated.
- NVD analysis. NVD status is Deferred, with no independent analysis of affected configurations beyond the CNA data.
- Real-world use. CISA's SSVC enrichment in the CVE record notes that a public proof of concept exists, marks the issue automatable and rates technical impact as total. No KEV listing appears in the evidence, and the evidence does not report abuse against real systems. The EPSS score shown on the GitHub advisory page is 0.312% (24th percentile).
The desk will follow up on any maintainer statement about regenerating output and on further escaping fixes. More coverage is in the Engineering Desk news.
Sources
Latest engineering analysis
6 min read
zod-msg-tools 0.1.4: npm malware hides an auth-bypassing SQL backdoor
A fake Zod helper on npm patches Node's HTTP server at runtime and adds a hidden endpoint that sits in front of your router and auth, runs queries on your database pools and, where the psql client is present, can reach OS command execution on Postgres deployments.
7 min read
Filament Curator picker search leaked media metadata across tenants
Filament Curator's picker search skipped the tenant scope, and an ungrouped orWhere chain also escaped the directory limit; upgrading is the only fix.
7 min read
array-flatten-utils on npm: malware loader that fires only in CI builds
A lookalike of array-flatten runs a native-addon loader at require() time, only in CI and build environments, where deploy tokens are stored.