CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-55391

CVE-2026-55391: Server-Side Request Forgery Bypass via DNS Rebinding in datamodel-code-generator

Alon Barad
Alon Barad
Software Engineer

Jul 29, 2026·6 min read·2 visits

Executive Summary (TL;DR)

A Time-of-Check to Time-of-Use (TOCTOU) DNS vulnerability in datamodel-code-generator allows remote attackers to bypass SSRF protections using DNS rebinding or IPv6-mapped IPv4 addresses, exposing internal networks.

CVE-2026-55391 is a server-side request forgery (SSRF) bypass vulnerability in the datamodel-code-generator package. The vulnerability occurs due to a Time-of-Check to Time-of-Use (TOCTOU) race condition during DNS resolution, combined with a failure to inspect embedded IPv4-in-IPv6 address mappings. By deploying a malicious DNS server with a low Time-To-Live (TTL) configuration, an attacker can bypass private address blocklists and coerce the application to connect to internal services or local endpoints.

Vulnerability Overview

The datamodel-code-generator package is a Python library used to generate structural structures, including Pydantic models, TypedDicts, and dataclasses, from remote schema definitions. To retrieve these definitions, the application supports fetching remote URLs when specified in the command-line interface or parsed as references within schemas. When the library is instructed to exclude private networks, a validation routine inspects the remote domain to confirm it resolves to a global, publicly routable IP address.

This implementation contains a fundamental vulnerability due to a Time-of-Check to Time-of-Use (TOCTOU) gap during network resolution. The library validates the target host during an initial DNS resolution phase but then relies on the underlying HTTP client library, which executes a second, independent DNS resolution during the socket connection phase. Because these phases are disconnected, a remote attacker can execute a DNS rebinding attack to bypass private network restrictions.

A secondary flaw also exists in how the validation engine processes IPv6-mapped IPv4 addresses. Specially constructed IPv6 structures mapping to local or private loops bypass the initial routability checks and allow connections to restricted endpoints.

Root Cause Analysis

The underlying vulnerability manifests in the get_body() function within src/datamodel_code_generator/http.py. When a target schema is fetched, the library employs a validation step to ensure that requested URLs resolve to global, public IP addresses before opening an HTTP connection. This security mechanism is intended to protect the host from Server-Side Request Forgery.

However, a severe Time-of-Check to Time-of-Use (TOCTOU) gap occurs. The validation step resolves the DNS domain name to verify its IP address using a standard socket call. Once validated, the library hands the raw string URL to the httpx HTTP client. The HTTP client then performs its own distinct DNS lookup to establish the actual network socket connection.

Because the DNS resolution is not pinned or cached between these two steps, an attacker can control the authoritative DNS server for the targeted domain. By specifying a Time-To-Live (TTL) of zero seconds, the attacker can return a safe, public IP during validation and a local or private IP during the connection phase. This forces the HTTP client to connect to local interfaces despite validation passing.

Additionally, the validation step relies on ip.is_global to flag unauthorized local IP addresses. However, IPv6 architectures allow embedding IPv4 targets inside IPv6 structures, such as mapped addresses (::ffff:127.0.0.1), compatible addresses (::127.0.0.1), or NAT64-mapped addresses. The operating system unrolls these to private targets, while standard library validation erroneously classifies the outer IPv6 shell as global.

Code Analysis

To understand the technical mechanics, consider the vulnerable logic flow. The application validated host targets by fetching IP arrays from the _get_ips_from_host function and verifying each IP using _is_safe_ip. This resolved DNS independently of the transport engine:

def _get_ips_from_host(host: str) -> tuple[IPv4Address | IPv6Address, ...]:
    # ...
    addr_infos = socket.getaddrinfo(host, None, ...)
    # ...

The fundamental issue was that after validating these IP instances, the library called httpx.get(current_url, ...) directly. It did not restrict httpx to the exact IP addresses that had just passed validation. This let httpx query DNS again during socket creation.

To remediate this, the developer implemented a custom transport backend that pins DNS resolution. The fixed transport uses the _PinnedNetworkBackend class to intercept connection attempts and enforce the use of pre-validated IP structures:

class _PinnedNetworkBackend:
    def __init__(
        self,
        *,
        pinned_host: str,
        pinned_ips: tuple[IPv4Address | IPv6Address, ...],
        backend: _NetworkBackend,
    ) -> None:
        self._pinned_host = _normalize_dns_host(pinned_host)
        self._pinned_ips = pinned_ips
        self._backend = backend
 
    def connect_tcp(
        self,
        host: str,
        port: int,
        # ...
    ) -> httpcore.NetworkStream:
        if _normalize_dns_host(host) != self._pinned_host:
            msg = f"Requested DNS host {host} does not match the validated host"
            raise OSError(msg)
 
        last_error: Exception | None = None
        for ip in self._pinned_ips:
            try:
                # Forces connection directly to the pre-validated IP address
                return self._backend.connect_tcp(
                    str(ip),
                    port,
                    timeout=timeout,
                    local_address=local_address,
                    socket_options=socket_options,
                )
            except Exception as exc:
                last_error = exc

This architecture forces the connection process to use the explicitly validated IPs, eliminating the TOCTOU gap entirely. Additionally, manual redirection loops were introduced so that any redirected targets must pass validation and pinning loops before access.

Exploitation

To initiate exploitation, an attacker configures an authoritative DNS server to manage a domain name under their control, such as rebound.attacker.com. The DNS server is programmed to return two different sets of IP addresses depending on the sequence or timing of incoming requests.

On the first query, which corresponds to the validation phase of datamodel-code-generator, the DNS server returns a public IP address. Because this public IP resolves to a globally routable resource, the validation checks succeed.

On the second query, which corresponds to the socket connection phase, the DNS server returns an internal IP address, such as 127.0.0.1 or the AWS link-local metadata address 169.254.169.254. Since the connection is initiated immediately after validation, the HTTP client connects directly to the internal endpoint.

By leveraging this sequence, an attacker can access sensitive configuration frameworks, metadata services, and databases running on loopback networks.

Impact Assessment

The impact of a successful SSRF attack via DNS rebinding is significant. If datamodel-code-generator is integrated into an enterprise microservice or an automated processing pipeline, the application could be used to extract highly sensitive structural data.

In cloud environments, this allow access to internal metadata APIs like the AWS/GCP Instance Metadata Service (IMDS). Attackers can request sensitive IAM credentials and session tokens, leading to potential cloud control plane compromise.

In local cluster deployments, the exploit can target internal resources that rely solely on network boundaries for security. Services that do not require authentication on localhost are especially vulnerable to manipulation and data exfiltration.

Remediation

To address this vulnerability, security administrators must upgrade datamodel-code-generator to version 0.63.0 or later. This version contains the socket pinning and address unwrapping mitigations.

If upgrading is not immediately possible, apply network-level controls. Configure outbound firewalls to block all traffic originating from the code-generation containers destined for internal subnets and metadata IP addresses.

Additionally, validation processes can be hardened by ensuring that remote references are fetched through an explicit gateway proxy. This proxy should perform its own strict DNS caching and enforce robust request boundaries.

Fix Analysis (1)

Technical Appendix

CVSS Score
7.5/ 10
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:N

Affected Systems

datamodel-code-generator python package

Affected Versions Detail

Product
Affected Versions
Fixed Version
datamodel-code-generator
koxudaxi
>= 0.50.0, < 0.63.00.63.0
AttributeDetail
CWE IDCWE-918 (SSRF), CWE-367 (TOCTOU)
Attack VectorNetwork
Attack ComplexityHigh
CVSS v3.1 Score7.5
Exploit StatusProof-of-Concept
CISA KEV StatusNot Listed

MITRE ATT&CK Mapping

T1190Exploit Public-Facing Application
Initial Access
T1005Data from Local System
Collection
CWE-918
Server-Side Request Forgery (SSRF)

The web application receives a URL or similar identifier from an upstream source and retrieves the contents at that URL, but it does not sufficiently ensure that the request is being sent to the intended destination.

Vulnerability Timeline

Initial mitigation implementation completed
2026-06-10
IPv6 embedded unwrapping successfully merged
2026-06-11
Official release of version 0.63.0 containing the patch
2026-07-28

References & Sources

  • [1]Fix Commit

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•14 minutes ago•CVE-2026-54690
8.2

CVE-2026-54690: Server-Side Request Forgery in datamodel-code-generator Remote Schema Resolution

CVE-2026-54690 (GHSA-954p-556p-r752) is a Server-Side Request Forgery (SSRF) vulnerability in the datamodel-code-generator Python library from version 0.9.1 to 0.61.0. The library silently resolves remote JSON Schema references ($ref) over HTTP/HTTPS without verifying the target hosts or IP addresses. Because it automatically follows redirects and permits requests to local and private networks by default, an attacker can submit a crafted schema to trigger connections to internal subnets, localhost, or cloud metadata endpoints. Retrieved sensitive data is subsequently parsed and reflected in the generated Python model files, resulting in local and private data disclosure.

Amit Schendel
Amit Schendel
0 views•7 min read
•about 1 hour ago•CVE-2026-54656
7.8

CVE-2026-54656: Arbitrary Code Execution in datamodel-code-generator via Unescaped Validator Configurations

CVE-2026-54656 is a high-severity arbitrary code execution vulnerability in the koxudaxi/datamodel-code-generator Python package. When processing validator metadata from external configuration files passed via the --extra-template-data argument, the code generator performs unescaped string interpolation into Pydantic v2 @field_validator decorators. This allows local attackers to construct malicious configuration files that inject arbitrary Python statements into generated models, executing code upon downstream import. This vulnerability has been resolved in version 0.60.2.

Alon Barad
Alon Barad
1 views•6 min read
•about 3 hours ago•CVE-2026-54653
8.8

CVE-2026-54653: Remote Code Execution via Code Injection in datamodel-code-generator

A critical code injection vulnerability exists in datamodel-code-generator from version 0.17.0 up to 0.60.1. The vulnerability allows remote attackers who supply a malicious JSON schema to execute arbitrary Python code. This occurs when the schema specifies a payload inside the 'default_factory' field extra, which is rendered directly into generated code without sanitization. When downstream processes load or import the output code, the evaluation of the class definition immediately triggers the execution of the injected code.

Alon Barad
Alon Barad
3 views•7 min read
•about 4 hours ago•CVE-2026-55389
7.5

CVE-2026-55389: Path Traversal and Security Control Bypass in datamodel-code-generator via Scheme Reference Resolution

An arbitrary local file read and path traversal bypass vulnerability in datamodel-code-generator before version 0.62.0 allows unauthenticated remote attackers to read arbitrary files via crafted JSON-Schema $ref references using the file:// scheme or directory traversal sequences.

Amit Schendel
Amit Schendel
4 views•4 min read
•about 5 hours ago•CVE-2026-54654
7.8

CVE-2026-54654: Python Code Injection in datamodel-code-generator via Comment Line-Break Escape

A vulnerability in the datamodel-code-generator library allows for unauthenticated remote code execution when generating code from malicious or untrusted schema specifications. By embedding special physical line terminators, such as carriage returns, vertical tabs, or form feeds, within template values, an attacker can break out of inline Python comment boundaries. The generated output file subsequently contains un-commented python instructions that execute automatically during module import.

Amit Schendel
Amit Schendel
7 views•5 min read
•about 6 hours ago•CVE-2026-62325
9.1

CVE-2026-62325: Authentication Bypass in goshs SFTP Server via Missing Password Check

A critical authentication bypass vulnerability in the SFTP server module of goshs version 2.1.3 allows remote, unauthenticated attackers to read, write, modify, or delete files on the target hosting environment. This vulnerability is caused by an incomplete logic check during initialization that falls back to a password-less configuration when an empty password string is specified.

Amit Schendel
Amit Schendel
4 views•6 min read