# fastapi-code-generator: Import-time RCE via response status-code key -> unescaped @app.get(..., responses={...}) dict

fastapi-code-generator emits response status-code keys unescaped into the responses={...} decorator dict, letting a crafted spec inject Python that executes when main.py is imported.

- Payout: Research
- Severity: critical
- Program: fastapi-code-generator
- Found by: Gal3m, mrostamipoor
- Disclosed: 2026-11-09
- CVE: CVE-2026-63469
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-6xmv-cjr5-w3q8
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-6xmv-cjr5-w3q8
- Tags: area:oss domain:oss impact:rce kind:research platform:ghsa sev:critical tech:python technique:chained technique:source-review vuln:rce

**Target:** Python code generator emitting FastAPI route decorators
**Root cause:** The generator writes each extra response's status-code key as a single-quoted string literal in the responses={...} dict without escaping the quote character, so a ' in the key closes the literal and allows expression concatenation.
**Steps:**
1. Craft an OpenAPI spec with an operation having a second (non-primary) response whose status-code key is `404' + (__import__("os").system('…') or "") + 'x`
2. Run fastapi-code-generator 0.8.0 on the spec to emit main.py
3. Import main.py (or start the ASGI server, which imports it)
4. The injected expression evaluates during decorator argument evaluation and the command runs
**How found:** Code-reading of the generator's emission of responses={...}: noticed the status-code key is a pure data field placed as a single-quoted literal without escaping, and that a valid-Python concat payload survives black/isort post-processing while syntax-breaking payloads only cause DoS.
**Exploitation:** Attacker supplies or influences an OpenAPI spec with a multi-response operation; the generated app contains a live expression in the @app.get responses dict that executes at import/startup, giving code execution in any app or CI that generates and serves the app.
**Insight:** Generated-code sinks include dict keys inside decorator arguments, not just string arguments and docstrings; test every spec field that lands in emitted Python, and prefer payloads that stay valid Python (concatenation with `or ""`) so formatters don't abort generation.

## Proof of concept (copied exactly from the original report)

**Injected responses dict key in generated decorator**

```
@app.get(
 '/u', response_model=None,
 responses={
 '404' + (__import__("os").system('…') or "") + 'x': {'model': Thing}
 },
)
def get_thing() -> None:
 pass
```

