datamodel-code-generator Vulnerable to SSRF Protection Bypass via DNS Rebinding
The `datamodel-code-generator` tool is vulnerable to a Server-Side Request Forgery (SSRF) protection bypass, identified as CVE-2026-55391, due to a time-of-check/time-of-use (TOCTOU) race condition through DNS rebinding, allowing attackers to access internal services like cloud instance metadata endpoints when processing attacker-influenced URLs.
The datamodel-code-generator Python library, specifically versions 0.62.0 and earlier, contains a high-severity Server-Side Request Forgery (SSRF) protection bypass vulnerability, tracked as CVE-2026-55391. Discovered by Hamza Haroon (thegr1ffyn), this flaw stems from a time-of-check/time-of-use (TOCTOU) race condition during DNS resolution, allowing a DNS rebinding attack. The library's anti-SSRF guard performs an initial IP validation that passes if a hostname resolves to a public IP; however, the subsequent httpx connection performs a separate, unpinned DNS resolution. An attacker can leverage this by controlling a low-TTL DNS record that resolves to a public IP during the validation phase and then switches to a private IP (e.g., 127.0.0.1 or 169.254.169.254) during the connection phase. This bypasses the intended private network protection, enabling access to internal network services, cloud instance metadata APIs, and internal host/port probing when the tool processes attacker-influenced URLs, such as those provided via the --url argument or remote $ref references in schemas. The vulnerability is present in versions up to 0.62.0 and was fixed in version 0.63.0.
Attack Chain
- An attacker registers a domain name (e.g.,
attacker.com) and configures its DNS records with a very low Time-To-Live (TTL). - The attacker configures the domain to initially resolve to a public, internet-routable IP address.
- The attacker influences a victim's
datamodel-code-generatorinstance (e.g., in a CI pipeline or local development environment) to fetch a URL pointing tohttp://attacker.com/schema.jsonvia the--urlcommand-line argument or a remote$refwithin a schema. - The
datamodel-code-generator's_validate_url_for_fetch()function performs the initial DNS resolution ofattacker.com(resolution #1). The public IP passes the SSRF guard's check. - Between validation and connection, the attacker rapidly changes the DNS record for
attacker.comto resolve to a private IP address (e.g.,127.0.0.1,169.254.169.254, or another internal network address). - The
httpx.get()function withindatamodel-code-generatorperforms its own, independent DNS resolution forattacker.com(resolution #2). Due to the low TTL and attacker's control, this resolution now returns the private IP address. httpxconnects to the private IP address, bypassing the initial validation and establishing an SSRF connection to an internal service or resource.- The attacker gains unauthorized access to internal HTTP services, reads cloud instance metadata credentials, or conducts internal network reconnaissance.
Impact
This Server-Side Request Forgery (SSRF) vulnerability (CWE-918) via a time-of-check/time-of-use (TOCTOU) resolution gap (CWE-367) affects any service or CI pipeline that executes datamodel-code-generator against attacker-influenced URLs. Successful exploitation allows attackers to bypass network segmentation controls, leading to the unauthorized disclosure of sensitive information such as cloud instance-metadata credentials (e.g., from 169.254.169.254). Attackers can also access internal-only HTTP services, perform port and host probing of the internal network, and reflect the content fetched from internal targets into the generated output, potentially exposing internal data. While specific victim counts are not available, the widespread use of datamodel-code-generator implies a broad attack surface for organizations using the tool in potentially vulnerable configurations.
Recommendation
- Upgrade
datamodel-code-generatorto version0.63.0or later immediately to remediate CVE-2026-55391. - Implement strict network egress filtering on systems running
datamodel-code-generatorto restrict outbound connections to only necessary and trusted external destinations, blocking access to private IP ranges, especially169.254.169.254. - Monitor DNS query logs for suspicious or rapid changes in IP resolution for external domains accessed by internal tools.
- Avoid running
datamodel-code-generatorin environments where--urlparameters or remote$refreferences can be influenced by untrusted external input.
Indicators of compromise
1
ip
| Type | Value |
|---|---|
| ip | 169.254.169.254 |