On this page (8 sections)
A critical flaw in fastapi-code-generator, a Python tool that builds FastAPI applications from OpenAPI files, lets a specially written operation summary inject code into the generated server. The injected code runs with the privileges of the server process when the affected endpoint is called. The issue is tracked as CVE-2026-63470 and is fixed in version 0.8.1.
If your team generates API servers from OpenAPI specs that come from partners, customers, public registries or any source you do not fully control, this one is for you. Servers generated with an old version may already contain the injected code, so upgrading the tool alone is not enough.
At a glance
What happened
According to the GitHub advisory, fastapi-code-generator takes each operation's summary field from the OpenAPI file and writes it into the generated route handler as a docstring. It wraps the text in triple double quotes but does not escape any triple quotes inside it. A summary that contains triple quotes can therefore end the docstring early and add its own Python expression to the body of the handler.
That expression runs each time the endpoint is called, not when the application starts. The advisory reports the behavior as verified on version 0.8.0 with Python 3 and FastAPI, and says a proof of concept was attached to the report. The research available for this article does not include any report of attacks in the wild, and only the advisory itself covers the story so far.
Technical details
The weakness is a classic output-encoding failure. The summary is meant to be plain data, but the generator pastes it into source code without neutralizing the characters that have meaning in that context. Anything that is data in the spec becomes code in the output.
The advisory describes a few details worth understanding:
- The generator formats its output with black and isort. Input that breaks Python syntax makes generation fail, so the dangerous case is input that stays syntactically valid.
- Valid injected code is written into the generated file and executes at call time, with the privileges of the server process.
- Other fields such as info.description, tags and parameter defaults are escaped. The operation description is not emitted into the function body. Models come from datamodel-code-generator and are escaped, with no code execution reported there.
- This is a different sink from the project's separate import-time issues, which involve the route path and additional response keys. Fixing those does not cover this one.
The CVSS v4 metrics on the advisory show network attack vector, low complexity, no privileges and no user interaction, with high impact to confidentiality, integrity and availability of the vulnerable system. In practice, the realistic precondition is that an attacker can influence the OpenAPI spec that you feed to the generator, and that the resulting endpoint is later called. The advisory's impact statement covers any app generated from an attacker-controlled or attacker-influenced spec.
Who is affected
Exposure depends on where your specs come from, not on whether the generator runs in production. The generator is a build-time tool, but its output is what ships.
| Workflow | Risk |
|---|---|
| You write your own spec and generate from it | Low, provided nobody untrusted can edit the spec or its summaries |
| Spec is edited by many contributors or merged from pull requests | Medium: review summary fields like code |
| Spec comes from partners, customers or third-party registries | Higher: summaries are attacker-influenced input |
| Generation runs in an automated pipeline or hosted service that accepts uploaded specs | Higher: also consider the build environment |
How to check your exposure
First find out which version of the tool is installed in each environment that generates code. This read-only command prints the installed version; anything below 0.8.1 is affected.
pip show fastapi-code-generatorNext, check where your pinned versions live. This searches common dependency files in a repository for the package name so you can see which pin or range applies.
grep -rn "fastapi-code-generator" --include="*.txt" --include="*.toml" --include="*.cfg" --include="*.lock" .Then look for specs that contain triple quotes in a summary line. Any hit deserves a manual look, since legitimate summaries almost never contain them. This is a heuristic search, not proof of compromise, and it assumes YAML or JSON specs with a summary key.
grep -rnE "summary.*\"\"\"" --include="*.yaml" --include="*.yml" --include="*.json" .What to do now
- Upgrade fastapi-code-generator to 0.8.1 or later in every developer machine, CI image and build container.
- Regenerate every application that was built with a version below 0.8.1, then redeploy the regenerated code.
- Search existing generated code and specs for summaries containing triple quotes, and review each hit by hand.
- Treat specs from outside your team as untrusted input: review summary fields in pull requests the same way you review code.
- Run generation and the generated app with least privilege, so a successful injection reaches as little as possible (no broad cloud credentials, limited file and network access).
- If you find a suspicious summary in a deployed app, follow your incident process: rotate secrets the server could read and review logs for calls to that endpoint.
This command upgrades the package in the active Python environment. Confirm the result with the version check above.
pip install --upgrade "fastapi-code-generator>=0.8.1"The fix is in the 0.8.1 release; the advisory references two commits, 49301db and b3b9bd6. The advisory's suggested approach is to escape the summary for a docstring context and to apply the same treatment to any free-text field rendered into a docstring.
Detection and monitoring
Because the code runs only when the endpoint is called, a vulnerable app can sit quietly until someone hits the route. Watch for unexpected child processes, outbound connections or file writes from your API worker processes, and for requests to rarely used endpoints that suddenly appear in access logs.
Add a CI step that fails the build when a spec contains triple quotes in free-text fields, and pin the generator version so older releases cannot slip back in. For internet-facing APIs, a website firewall and regular security scans add outside-in visibility, though neither replaces fixing the generator and regenerating the code. The guide on checking whether a site is hacked covers the signs to look for if you suspect a deployed app ran injected code.
Timeline
- Jul 1, 2026: advisory GHSA-h667-4jj2-cgv4 published in the koxudaxi/fastapi-code-generator repository.
- Nov 3, 2026: CVE-2026-63470 published by the National Vulnerability Database.
- Nov 9, 2026: advisory published to and reviewed in the GitHub Advisory Database.
The research does not state the date version 0.8.1 was released, so check the release page for that detail.
Sources
This article is based on the public sources below. Details can change as vendors and researchers publish more; check the original advisories before acting on version numbers.
