{"id":"CVE-2026-55391","aliases":["CVE-2026-55391","GHSA-vx7x-vcc2-c44g","PYSEC-2026-3565"],"related":[],"kind":"vulnerability","state":"published","title":"datamodel-code-generator vulnerable to SSRF protection bypass via DNS rebinding","summary":"datamodel-code-generator generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON, YAML, or CSV. Prior to 0.63.0, datamodel-code-generator validates a URL host once in src/datamodel_code_generator/http.py through get_body, _validate_url_for_fetch, and _get_ips_from_host, but then lets httpx resolve the host again for the connection, allowing DNS rebinding to bypass allow_private_network=False and reach internal services. This issue is fixed in version 0.63.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"datamodel-code-generator generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON, YAML, or CSV. Prior to 0.63.0, datamodel-code-generator validates a URL host once in src/datamodel_code_generator/http.py through get_body, _validate_url_for_fetch, and _get_ips_from_host, but then lets httpx resolve the host again for the connection, allowing DNS rebinding to bypass allow_private_network=False and reach internal services. This issue is fixed in version 0.63.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`datamodel-code-generator`'s anti-SSRF guard validates the resolved IP of a fetch target once and then lets `httpx` perform its own independent DNS resolution to connect, so the validated address is never pinned. A hostname that resolves to a public IP at validation time and a private IP at connection time (DNS rebinding) bypasses the guard and reaches loopback, link-local cloud-metadata endpoints (`169.254.169.254`), and other internal services — even with the default `allow_private_network=False`. This is a server-side request forgery reachable when the tool fetches an attacker-influenced URL (remote `$ref`, or `--url`).\n\n### Details\n\nIn `src/datamodel_code_generator/http.py`, `get_body()` calls `_validate_url_for_fetch()`, which resolves the host via `_get_ips_from_host()` (`socket.getaddrinfo`) and rejects non-global addresses:\n\n```python\nips = _get_ips_from_host(host)            # resolution #1 (validation)\nif not ips: return\nif all(_is_safe_ip(ip) for ip in ips): return\nraise SchemaFetchError(...)               # blocks private/link-local/reserved\n```\n\nIt then connects with a separate, independent resolution:\n\n```python\nresponse = httpx.get(current_url, ...)    # resolution #2 (connection) -- NOT pinned to #1\n```\n\nNothing ties the connection to the IP that passed validation. Between the two resolutions a low-TTL attacker-controlled record can flip from a public address (passes the guard) to a private one (used by the connection). The redirect-handling loop in the same function does correctly re-validate each redirect URL, so this is specifically a TOCTOU/rebinding gap in the host-to-IP check, not a redirect issue.\n\n### PoC\n\nSelf-contained reproducer: https://gist.github.com/thegr1ffyn/c1d54dd6ff2a4c0d7d0dabe00c4985f4 \nIt starts a loopback HTTP server standing in for an internal target and patches `socket.getaddrinfo` to return a public IP on the guard's lookup and `127.0.0.1` on httpx's  the standard deterministic way to demonstrate this TOCTOU class (the real-world trigger is a low-TTL rebinding DNS record the attacker controls). \n\nReachability in normal use: the attacker registers a rebinding hostname and gets the tool to fetch `http://that-host/schema.json` either via `--url` or via a remote `$ref` in a supplied schema (remote refs are fetched on the default configuration).\n\n### Impact\n\nServer-side request forgery (CWE-918) via a time-of-check/time-of-use resolution gap (CWE-367). Any service or CI pipeline that runs `datamodel-code-generator` against attacker-influenced URLs is affected, including deployments that rely on the default private-network protection. Consequences include reading cloud instance-metadata credentials (`169.254.169.254`), reaching internal-only HTTP services, and port/host probing of the internal network, the document fetched from the internal target is also parsed and can be reflected into the generated output.\n\n### Maintainer status\n\nConfirmed by maintainer review and regression tests. The private fix PR was merged and released in `0.63.0`: https://github.com/koxudaxi/datamodel-code-generator-ghsa-vx7x-vcc2-c44g/pull/1\n\nFix summary: pin the validated DNS result set during the HTTP fetch so a host cannot resolve to a safe address during validation and a different address during connection.\n\nRelease status: fixed in `0.63.0`; `0.62.0` and earlier are affected.\n\nValidation: `uv run --group test --extra http pytest tests/test_http.py` passed locally for DNS pinning and URL-fetch regression coverage; `uv run --group fix ruff check src/datamodel_code_generator/http.py tests/test_http.py` passed.\n\nSubmitted by: Hamza Haroon (thegr1ffyn)","format":"markdown","source":"ghsa"},{"lang":"es","text":"datamodel-code-generator genera modelos Pydantic v2, dataclasses, TypedDict y msgspec.Struct a partir de OpenAPI, JSON Schema, GraphQL, Avro, Protobuf y JSON, YAML o CSV sin procesar. Antes de la versión 0.63.0, datamodel-code-generator valida el host de una URL una vez en src/datamodel_code_generator/HTTP.py a través de get_body, _validate_url_for_fetch y _get_ips_from_host, pero luego permite que httpx resuelva el host de nuevo para la conexión, permitiendo la revinculación de DNS para eludir allow_private_network=False y alcanzar servicios internos. Este problema está solucionado en la versión 0.63.0.","source":"nvd"}],"published":"2026-07-28T21:45:39.058Z","modified":"2026-10-23T23:10:00.157Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:N","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:N","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:N","score":7.5,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:N","score":7.5,"rating":"HIGH"}],"cwes":["CWE-350","CWE-367","CWE-918"],"affected":[{"ranges":[{"version":"< 0.63.0","status":"affected"}],"vendor":"koxudaxi","product":"datamodel-code-generator","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.63.0"}],"ecosystem":"PyPI","package":"datamodel-code-generator","purl":"pkg:pypi/datamodel-code-generator","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.63.0"}],"vendor":"koxudaxi","product":"datamodel-code-generator","cpe":"cpe:2.3:a:koxudaxi:datamodel-code-generator:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.63.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-vx7x-vcc2-c44g","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator/commit/25c8b7e497419eb20b230fa3318c04f9bebc5a6f","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.63.0","tags":["release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://gist.github.com/thegr1ffyn/c1d54dd6ff2a4c0d7d0dabe00c4985f4","tags":["exploit","third-party-advisory"],"sources":["cvelist","nvd"]},{"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-vx7x-vcc2-c44g","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-55391","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-29T13:29:52.729Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-55391","url":"https://www.cve.org/CVERecord?id=CVE-2026-55391","licence":"CVE Terms of Use","modified":"2026-07-29T13:30:14.117Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-vx7x-vcc2-c44g","url":"https://github.com/advisories/GHSA-vx7x-vcc2-c44g","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:12.330Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-55391","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-55391","licence":"Public domain","modified":"2026-10-23T23:10:00.157Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-3565","url":"https://osv.dev/vulnerability/PYSEC-2026-3565","licence":"CC-BY-4.0","modified":"2026-08-04T14:30:15.997Z"}],"updatedAt":"2026-11-25T22:59:30.390Z","epss":{"score":0.00236,"percentile":0.15686,"date":"2026-12-01T12:00:22.000Z"}}