CVE-2026-63470: fastapi-code-generator: Call-time RCE via operation summary -> unescaped route-handler docstring
fastapi-code-generator before 0.8.1 writes an operation's summary into the generated handler as a triple-quoted docstring without escaping triple quotes. A summary containing three double quotes breaks out and injects a Python expression that runs each time the endpoint is called. Upgrade to 0.8.1.
Published Nov 9, 2026 · Analysis Nov 9, 2026
What an attacker can do
The generator turns each operation's summary into the route handler's docstring. It does not escape the three double quotes. A summary such as x""" + (__import__("os").system('...') or "") + """y closes the docstring, runs the expression and opens a new string. In the generated function this becomes an expression statement in the handler body.
Unlike the sibling flaws in the same tool, nothing executes at import. The code runs when the route handler is called, so it fires when someone, or the attacker, hits the affected endpoint. The attacker needs to control or influence the OpenAPI spec that produces the app. They then get code execution on the server in the process that serves the API, usually with access to its environment, database credentials and network. Black and isort process the output, so a payload with invalid syntax only aborts generation. The operation description is not written into the function body, so only the summary is a sink. The reporter verified 0.8.0.
Who is affected
fastapi-code-generator before 0.8.1, verified on 0.8.0. Every operation with a summary in the spec produces a docstring, so any spec you do not control can carry the payload. Check the version:
pip show fastapi-code-generatorIn generated route handlers, look at the first statement of each function body. A docstring that is followed by + or a call such as __import__ is a sign of tampering.
fastapi-code-generator
- Ecosystem
- PyPI
- Affected
- < 0.8.1
- Fixed in
- 0.8.1
- Check
pip show fastapi-code-generator
How to fix it
Upgrade to 0.8.1:
pip install --upgrade "fastapi-code-generator>=0.8.1"The 0.8.1 release corrects how operation summaries are escaped when written into docstrings. The fix commits are 49301dbdb82170d7f50877419d994b05cb1fa2bc and b3b9bd66e0b0c4d8c686fda700258104615a1332. The reporter's suggested approach is to escape triple quotes and backslashes through repr, or strip triple quotes, and to do the same for any free text that ends up in a docstring. Regenerate apps that were built from untrusted specs with an older version and redeploy them.
How to tell if you were hit
Search spec files for summary values that contain three double quotes in a row. Search generated handlers for docstrings joined to expressions with +, or for __import__, os.system and subprocess calls in a function body. Because the payload runs at call time, check access logs for requests to the affected route that line up with unexpected child processes or outbound connections from the API process. Rotate secrets reachable by the API process if an untrusted spec was used.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
fastapi-code-generator (koxudaxi) emits an operation's summary as the generated route handler's docstring, using a triple-quoted string without escaping """. A """ in the summary closes the docstring and, via concatenation, injects a live expression that becomes an expression statement in the handler body -- which runs when the route handler is CALLED (the endpoint is hit). The summary is a pure data field. Verified on fastapi-code-generator 0.8.0 / Python 3 / FastAPI.
Details
def get_thing() -> None:
(
"""
x"""
+ (__import__("os").system('…') or "")
+ """y
"""
)
passThe generator post-processes with black/isort, so a syntax-breaking payload aborts generation; a valid-Python breakout ("""+expr+""", kept valid with (… or "")) is written and executes at call time. info.description, tags, parameter defaults are escaped; operation description is not emitted into the function body; the summary in the handler docstring is the unescaped sink. Models come from datamodel-code-generator (repr-escaped, no RCE).
Not a duplicate: distinct product from OpenAPI Generator's python-fastapi; and distinct field/sink from the route path -> @app.get('…') decorator (import-time) in the same product -- this is the operation summary in the handler docstring (call-time).
PoC
reproduce.sh (+ make_spec.py) attached: generates the app and calls the route handler; the injected expression runs and writes a marker. Verified on 0.8.0.
Impact
Code execution on the server when the affected endpoint is invoked, in any app generated with fastapi-code-generator from an attacker-controlled or attacker-influenced spec.
Suggested fix
Escape the summary for the docstring context (escape """/backslashes via repr, or strip triple-quotes) before emitting it as the handler docstring; apply the same to any free-text field rendered into a docstring. maintainer-report.txt make_spec.py reproduce.sh
Credited to Gal3m, mrostamipoor.
Questions
- When does the injected code run?
When the affected route handler is called, not at import. Someone has to send a request to that endpoint, which the attacker can do if the route is reachable.
- Is it the same bug as CVE-2026-63471?
No. That one injects through the route path in the decorator and runs at import. This one injects through the operation summary in the docstring and runs at call time. Both are fixed in 0.8.1.
- Which version fixes CVE-2026-63470?
0.8.1. Earlier versions are affected, and the reporter verified 0.8.0.
- Is it exploited in the wild?
No source we read reports exploitation, and the entry has no CISA KEV record.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
Coverage on the Beam blog
- CVE-2026-69157: Atomic Server `/setup` Invite Grants Drive-Wide Write
- CVE-2026-130001: Ruby Mustache Template RCE in ≤1.1.2
- CVE-2026-118740: .NET Aspire Dashboard NotFound Route Deletes Telemetry Without Auth
- CVE-2026-95860: node-opcua RBAC Fail-Open Lets Anonymous Write and Call
- Wiz Cyber Model Arena: What Offensive Coding-Agent Scores Actually Mean
