fastapi-code-generator CVE-2026-63471: hostile OpenAPI specs run code at import
A code-injection flaw in fastapi-code-generator turns an untrusted OpenAPI spec into code that runs when the generated app starts, and upgrading alone does not clean output generated earlier.
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
Fixed: fastapi-code-generator 0.8.1 escapes OpenAPI route paths, and every earlier version is affected by CVE-2026-63471. Teams that generate FastAPI apps from specs they do not fully control, including partner, vendor, customer or automatically fetched specs, should upgrade now. They should then review or regenerate any main.py produced with an older version, because the injected code persists in that file and runs when it is imported.
What happened
The pip package fastapi-code-generator produces a FastAPI application from an OpenAPI file. Versions below 0.8.1 write the OpenAPI path unescaped into a single-quoted @app.get('…') decorator string in the generated main.py. A quote character in the path therefore closes the string, which lets an attacker splice a Python expression into the decorator argument (GitHub advisory GHSA-p2mm-64f6-gmpp).
The issue is tracked as CVE-2026-63471 and carries a CVSS v4 base score of 9.3. Input that breaks Python syntax only makes generation fail. Input that stays syntactically valid is written into main.py and runs with the privileges of the application or CI process when that module is imported (NVD). No HTTP request is needed.
Version 0.8.1 is the first patched release. Its release notes list the route-path escaping fix under GHSA-p2mm-64f6-gmpp. The same release also fixes two related escaping problems that have separate advisories: operation-summary docstrings (GHSA-h667-4jj2-cgv4) and additional-response status-code keys (GHSA-6xmv-cjr5-w3q8). A reproduction script is attached to the advisory.
Why it matters
This is a build-time code generator, not a runtime library. That changes both who is exposed and how the fix works.
- Exposure depends on where the spec comes from. The 9.3 score assumes a network attacker with no privileges. In practice the attacker has to control or influence the OpenAPI document you feed the generator. Specs written in-house and reviewed in pull requests carry little risk. The risky cases are:
- specs supplied by partners, vendors or customers;
- specs pulled automatically from a URL or registry in CI;
- multi-tenant tooling that generates code from uploaded specs.
- The payload outlives the bug. The injected code is written into source. A
main.pygenerated before the upgrade still contains it, and it runs every time an ASGI server, a test runner or a CI step imports that file. Upgrading to 0.8.1 protects only future generation. - CI is a prime target. Generate-then-test pipelines import the module immediately, inside a process that often holds deploy keys, registry tokens and cloud credentials.
- This is not OpenAPI Generator. The advisory says the flaw is distinct from OpenAPI Generator's python-fastapi backend, which is a different codebase.
Engineering assessment
Our assessment: for most teams this is a moderate, contained issue that the 9.3 score overstates. For the subset that generates code from untrusted or externally sourced specs, it is a genuine high-severity supply-chain risk, and it is easy to under-remediate.
The score treats the spec as network-reachable input. For a typical team the spec sits in their own repository and is edited by their own engineers, and in that setting anyone who can change the spec can usually change main.py directly. The case that matters is spec-as-data:
- integration platforms that scaffold services from partner APIs;
- internal developer portals;
- government or enterprise programmes that receive interface definitions from suppliers;
- pipelines that regenerate code on every upstream spec change.
In those settings, a party you do not otherwise grant code execution gains it.
The overlooked part is cleanup. A normal library CVE ends with upgrade and restart. Here the generated file is the artefact that carries the payload, and it is often committed and then never regenerated. So the remediation unit is the output, not the dependency. Teams should treat any main.py generated before 0.8.1 from an externally influenced spec as untrusted until it has been reviewed or regenerated.
The fact that 0.8.1 also closes the docstring and response-key sinks suggests the generator's escaping was a systemic weakness rather than a one-off. Teams should review all generated output, not only route decorators.
Upgrade compatibility risk looks low, since 0.8.1 is a patch release that changes escaping. That conclusion is inferred, not stated: the evidence does not describe behavioural changes. Regenerated code may differ textually from older output, so expect diffs and review them.
Is this you?
- You use
fastapi-code-generatorat any version below 0.8.1, locally, in CI or in internal tooling. - You generate from OpenAPI specs that come from outside your team: partners, vendors, customers, uploads or URLs fetched automatically.
- Your pipeline generates
main.pyand then imports, tests or serves it without human review. - You have committed generated
main.pyfiles that were produced with an older version from a spec you did not author. - You only use OpenAPI Generator's python-fastapi backend: this advisory does not cover that product.
What to do
- Inventory now. Find every place the generator is installed:
pip show fastapi-code-generatorpip list | grep -i fastapi-code-generator- Search lockfiles and requirements files, CI images and developer tooling containers.
- Upgrade to 0.8.1. Run
pip install --upgrade "fastapi-code-generator>=0.8.1"and pin it in lockfiles and CI images. This is the vendor fix. - Audit existing generated output. For each
main.pygenerated before the upgrade from an externally influenced spec, inspect the route decorators:grep -n "@app\." main.py. The first argument should be a single plain string literal. Treat any concatenation, function call or other expression there as a potential compromise. Review docstrings and response-status keys as well, because 0.8.1 fixed those sinks too. - Regenerate with 0.8.1 where practical, and review the diff against the committed file.
- If you find injected code, treat the hosts and CI runners that imported the file as compromised. Rotate the credentials available to those processes. (Not vendor guidance.)
- Harden spec intake. These steps are not vendor guidance:
- Validate that OpenAPI path strings contain only expected URL characters before generation.
- Run generation and the first import in a sandboxed CI job with no secrets.
- Require human review of generated code before it is merged.
What we don't know yet
- Timeline. The project advisory and the 0.8.1 release show 1 July 2026, while the CVE record was published on 2026-11-03. The evidence does not explain the gap, or whether scanners flagged vulnerable versions during it.
- Sibling advisories. The evidence does not give CVE identifiers, severity or affected ranges for GHSA-h667-4jj2-cgv4 and GHSA-6xmv-cjr5-w3q8.
- Verified versions. Only 0.8.0 is stated as verified. The affected range is given as everything below 0.8.1.
- Workarounds and detection. No workaround other than upgrading is published, and there is no official way to detect already-generated malicious files.
The desk will check for updates on the sibling advisories and any maintainer guidance on auditing existing output.
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.