On this page (7 sections)

fastapi-code-generator, a Python tool that builds FastAPI applications from OpenAPI files, has a critical code injection flaw tracked as CVE-2026-63471. The generator writes each OpenAPI path into the generated route decorator without escaping quotes, so a specially crafted path can add code that runs as soon as the generated module is imported. The maintainers fixed it in version 0.8.1.

If you generate FastAPI services from OpenAPI specs that someone else writes or influences, or you run that generation in CI, this affects you. The GitHub advisory is the main source for the details below.

What happened

The advisory describes how the generator turns an OpenAPI path into a Python route decorator of the form @app.get('...'). The path is placed inside a single-quoted string, and a quote character inside the path is not escaped. A path containing a quote can therefore close the string early and add a valid Python expression to the decorator argument.

Decorator arguments are evaluated when the module loads. The advisory notes that the ASGI server imports the generated main.py at startup, so the injected expression runs with no incoming request needed. The advisory reports it was verified on version 0.8.0. The advisory's own severity estimate and the final CVSS 9.3 score both rate it critical.

Why this class of bug matters

This is a code generation injection. The tool treats the OpenAPI path as plain data, but it pastes that data into source code. If the data is not escaped for the target language, data becomes code. The same pattern appears in template engines, SQL builders and shell wrappers.

Details from the advisory worth knowing:

  • Input that breaks Python syntax only makes generation fail, because the output is post-processed with black and isort. The advisory calls this a denial of service, not code execution.
  • Input that stays syntactically valid is written to the file and executes when the module is imported, with the privileges of the application or the CI process that imports it.
  • Other fields, such as the description, tags and parameter defaults, are escaped. The path in the route decorator was the unescaped sink.
  • The CVE record describes this path sink as distinct from the project's separate operation-summary docstring and additional-response-key sinks. The research does not say whether those other sinks are fixed in 0.8.1, so check the project's own advisories for them.

Who is realistically exposed

Exploitation needs the attacker to control or influence the OpenAPI document that you feed to the generator. That makes the risk depend on where your specs come from. Higher-risk setups include:

  • Platforms or internal tools that accept OpenAPI files from customers, partners or other teams and generate services from them.
  • CI pipelines that regenerate code from a spec pulled from a third-party repository, a vendor portal or a pull request from an outside contributor.
  • Build jobs with access to secrets, deploy keys or cloud credentials, since injected code runs with the privileges of that process.
  • Developer machines that generate and then run code from specs downloaded from unknown sources.

If you write your own specs, keep them in a repository only your team can change, and never generate from outside input, your practical exposure is lower. You should still upgrade, because specs can change through review gaps, compromised accounts or dependency updates.

How to check if you are affected

Start by finding where the package is installed. This read-only command shows the installed version in the current Python environment. Look for a version below 0.8.1.

Show the installed fastapi-code-generator version (run in each virtualenv, container or CI image)Shell
pip show fastapi-code-generator

Then search your repositories for places where the package is pinned or called, so you also catch CI jobs and Dockerfiles. This grep lists files that mention it.

Find references to the package in a project tree (run from the repository root)Shell
grep -rn "fastapi-code-generator" --include="*.txt" --include="*.toml" --include="*.cfg" --include="Dockerfile*" --include="*.yml" --include="*.yaml" .

Also review any generated main.py files and the specs behind them. Route paths that contain a single quote, a plus sign or parentheses are not normal and deserve a look. Generated output committed to a repository is worth reviewing even after you upgrade, since it was produced by the vulnerable version.

What to do now

  1. Upgrade fastapi-code-generator to 0.8.1 or later in every environment, including CI images and lockfiles.
  2. Rebuild and redeploy any service whose code was generated by an older version, after regenerating it with 0.8.1.
  3. Review OpenAPI specs that came from outside your team and look for route paths with quotes or code-like characters.
  4. Run generation in a sandbox with no secrets, minimal network access and a throwaway filesystem when the spec is not fully trusted.
  5. Treat specs from external sources as untrusted input: require review before generation and validate path characters.
  6. If a suspicious spec was ever generated and imported, rotate the credentials that process could reach and check build and server logs for unexpected activity.

This command upgrades the package in the active environment. Run it in each environment you found above, then re-run the version check.

Upgrade fastapi-code-generator to the fixed release (run in the affected environment)Shell
pip install --upgrade "fastapi-code-generator>=0.8.1"
Caution. Regenerating code can change your application's output. Run your tests before deploying, and restart or redeploy the ASGI service only after the new generated code is in place.
Tip. If you pin dependencies, update the pin in requirements or your lockfile to 0.8.1 or higher so a later rebuild does not pull the old version back in. The fix is in the 0.8.1 release.

Detection and monitoring

This bug runs at import time inside your build or application process, so it is not something an outside scan can see in a deployed site. Focus on your own pipeline:

  • Alert on changes to OpenAPI files that add unusual characters to path keys.
  • Watch CI logs for generation steps that make unexpected network calls or spawn processes.
  • Keep dependency scanning on in your repositories so older fastapi-code-generator versions are flagged.
  • Limit which accounts can modify specs and the workflows that consume them.

For the public-facing side of services built this way, a security scan can check exposed endpoints and headers, and monitoring can alert you to certificate, DNS and header changes. Neither replaces patching the generator itself.

Timeline

Dates as listed in the GitHub advisory
DateEvent
Jul 1, 2026Advisory published in the koxudaxi/fastapi-code-generator repository
Nov 3, 2026Published by the National Vulnerability Database
Nov 9, 2026Published to the GitHub Advisory Database, reviewed and last updated
Only one independent publisher, the GitHub advisory, is covered in our research so far. We found no reports of exploitation in the wild, but absence of reports is not proof that it has not happened.

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.

  1. CVE-2026-63471 - GitHub Advisory Databasegithub.com
  • fastapi
  • code injection
  • openapi
  • python
  • supply chain
  • CVE-2026-63471