{"id":"CVE-2026-54691","aliases":["CVE-2026-54691","GHSA-rfr2-mq9m-x2qx","PYSEC-2026-3564"],"related":[],"kind":"vulnerability","state":"published","title":"datamodel-code-generator vulnerable to SSRF via --url: no host/IP validation, follows redirects","summary":"datamodel-code-generator generates Python data models from schema definitions. From 0.9.1 until 0.61.0, src/datamodel_code_generator/http.py http.get_body accepts --url targets and redirect chain targets without host/IP validation, allowing server-side request forgery against loopback, private, link-local, metadata, and other network-accessible resources. This issue is fixed in version 0.61.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"datamodel-code-generator generates Python data models from schema definitions. From 0.9.1 until 0.61.0, src/datamodel_code_generator/http.py http.get_body accepts --url targets and redirect chain targets without host/IP validation, allowing server-side request forgery against loopback, private, link-local, metadata, and other network-accessible resources. This issue is fixed in version 0.61.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`datamodel-code-generator`'s built-in HTTP fetcher (`http.get_body`) issues an `httpx.GET` against any URL passed to `--url` (or reached via a redirect chain) with **no allow-list, no deny-list, no IP/host validation, and `follow_redirects=True`**. Loopback addresses, RFC1918 ranges, link-local (`169.254.169.254` cloud metadata), unique-local IPv6 and any other network-accessible target are all reachable. The JSON/YAML response body is parsed as a schema and reflected into the generated `.py` source, exfiltrating the response to anyone with access to that file (commonly committed to a repository).\n\n### Details\n\nSink: `src/datamodel_code_generator/http.py`, `get_body` (lines 31–61, at tag `0.60.1` / commit `a321547e`):\n\n```python\ndef get_body(url, headers=None, ignore_tls=False,\n             query_parameters=None, timeout=DEFAULT_HTTP_TIMEOUT) -> str:\n    httpx = _get_httpx()\n    try:\n        response = httpx.get(\n            url,\n            headers=headers,\n            verify=not ignore_tls,\n            follow_redirects=True,          # (A)\n            params=query_parameters,\n            timeout=timeout,\n        )\n    except Exception as e:\n        ...\n    if response.status_code >= 400:\n        ...\n    content_type = response.headers.get(\"content-type\", \"\").lower()\n    if \"text/html\" in content_type:\n        raise SchemaFetchError(...)         # (B) — only filter\n    return response.text                    # (C) → embedded in generated.py\n```\n\n- (A) follows redirects unconditionally — a public URL → 302 → internal address chain works.\n- (B) the only filter is rejecting `text/html`. Non-HTML internal endpoints (JSON APIs, cloud metadata, admin services) pass through.\n- (C) the response body becomes the schema; its `title`, `description`, `properties`, etc. land in the generated `.py` as class attributes and `Field(description=...)` strings.\n\n`get_body` is called by `parser/base.py:1326` (`_get_text_from_url`), which is reached from CLI argument `--url <URL>`. (The `$ref` path is a separate advisory — see GHSA-D.)\n\nOnly affects users who installed the `[http]` extra (`pip install 'datamodel-code-generator[http]'`).\n\n### PoC\n\nA self-contained one-file PoC available here:\nhttps://gist.github.com/thegr1ffyn/18de777d6c800a3b47715425e3f3e8f5\n\n### Impact\n\n**Who is impacted.** Anyone who runs `datamodel-codegen` with a `--url` they didn't fully verify, or who runs it inside a network with reachable internal services. Realistic scenarios:\n\n1. **Trojan documentation / README.** A blog post or README example reads `datamodel-codegen --url https://schemas.example.com/user.json -o user.py`. The attacker controls `example.com`, redirects to `http://169.254.169.254/latest/meta-data/iam/security-credentials/<role>`, and the IAM credentials end up as a docstring in `user.py`.\n2. **Internal port scan / disclosure.** Iterating `--url http://127.0.0.1:<port>/health` probes localhost services; non-HTML, non-error responses confirm a service and leak its body into the generated file.\n3. **CI poisoning.** A PR adds a Makefile rule that calls `datamodel-codegen --url $(SCHEMA_URL)`; the CI runner reaches every internal service in its VPC and the response lands in PR artifacts.\n\n**Suggested fix.** Resolve the URL host, reject loopback / private / link-local / multicast / reserved IPs by default, disable redirects by default (`follow_redirects=False`), re-validate after each redirect if the user opts into following them, and add an `--allow-private-network` flag for opt-in legitimate use.\n\n### Maintainer resolution\n\nThis report was fixed together with GHSA-954p-556p-r752 by the private security PR koxudaxi/datamodel-code-generator-ghsa-rfr2-mq9m-x2qx#1, merged into the public repository as 5fdba4a09f2d7a9996a504975b7ef7d63e3715bb. Follow-up generated-file and coverage fixes were merged in koxudaxi/datamodel-code-generator#3279 and docs were synced in #3280. The patched release is 0.61.0.\n\nThe patch hardens the shared HTTP fetcher used by both direct CLI `--url` fetching and remote JSON Schema/OpenAPI `$ref` resolution:\n\n- validates HTTP(S) URLs before fetching;\n- blocks localhost, loopback, private, link-local, reserved, and other non-public network targets by default;\n- disables automatic redirect following and validates each redirect target before requesting it;\n- adds `--allow-private-network` / `allow_private_network=True` as an explicit opt-in for trusted internal schema endpoints.\n\nRemote `$ref` fetching remains controlled by `--allow-remote-refs`; non-public/internal targets additionally require `--allow-private-network`.\n\nSubmitted by: Hamza Haroon (thegr1ffyn)","format":"markdown","source":"ghsa"},{"lang":"es","text":"datamodel-code-generator genera modelos de datos Python a partir de definiciones de esquema. Desde la versión 0.9.1 hasta la 0.61.0, src/datamodel_code_generator/http.py http.get_body acepta objetivos --url y objetivos de cadena de redirección sin validación de host/IP, lo que permite la falsificación de petición del lado del servidor contra recursos de loopback, privados, de enlace local, de metadatos y otros recursos accesibles por red. Este problema está solucionado en la versión 0.61.0.","source":"nvd"}],"published":"2026-07-28T21:29:52.197Z","modified":"2026-10-23T23:10:00.157Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N","score":8.2,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N","score":8.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N","score":8.2,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N","score":8.2,"rating":"HIGH"}],"cwes":["CWE-918"],"affected":[{"ranges":[{"version":">= 0.9.1, < 0.61.0","status":"affected"}],"vendor":"koxudaxi","product":"datamodel-code-generator","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0.9.1","status":"affected","fixed":"0.61.0"}],"ecosystem":"PyPI","package":"datamodel-code-generator","purl":"pkg:pypi/datamodel-code-generator","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0.9.1","status":"affected","fixed":"0.61.0"}],"ecosystem":"PyPI","package":"datamodel-code-generator","purl":"pkg:pypi/datamodel-code-generator","source":"pysec"}],"references":[{"url":"https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-rfr2-mq9m-x2qx","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator/commit/5fdba4a09f2d7a9996a504975b7ef7d63e3715bb","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.61.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/datamodel-code-generator","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-rfr2-mq9m-x2qx","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54691","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-29T14:18:17.626Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54691","url":"https://www.cve.org/CVERecord?id=CVE-2026-54691","licence":"CVE Terms of Use","modified":"2026-07-29T14:18:45.531Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-rfr2-mq9m-x2qx","url":"https://github.com/advisories/GHSA-rfr2-mq9m-x2qx","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:12.018Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54691","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54691","licence":"Public domain","modified":"2026-10-23T23:10:00.157Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-3564","url":"https://osv.dev/vulnerability/PYSEC-2026-3564","licence":"CC-BY-4.0","modified":"2026-08-04T14:30:15.062Z"}],"updatedAt":"2026-11-25T22:59:30.388Z","epss":{"score":0.00259,"percentile":0.18848,"date":"2026-12-01T12:00:22.000Z"}}