<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Datamodel-Code-Generator - CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/vendors/datamodel-code-generator/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata. Fed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 28 Jul 2026 21:54:03 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/vendors/datamodel-code-generator/feed.xml" rel="self" type="application/rss+xml"/><item><title>`datamodel-code-generator` Vulnerable to Code Injection via `default_factory` Field</title><link>https://feed.craftedsignal.io/briefs/2026-07-datamodel-code-generator-rce/</link><pubDate>Tue, 28 Jul 2026 21:54:03 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2026-07-datamodel-code-generator-rce/</guid><description>The `datamodel-code-generator` library is vulnerable to code injection (CVE-2026-54653) when generating Python models from attacker-controlled schemas (e.g., JSON Schema, OpenAPI, YAML). This occurs because the `default_factory` schema field's value is interpolated directly as a raw Python expression into the generated code, allowing an attacker who controls the input schema to achieve arbitrary Python code execution within the consumer's process at module import time, affecting developers or CI pipelines that process untrusted schemas.</description><content:encoded><![CDATA[<p><code>datamodel-code-generator</code> versions 0.17.0 through 0.60.1 are affected by a high-severity code injection vulnerability (CVE-2026-54653) that allows for arbitrary Python code execution. This vulnerability arises when the tool generates Python models from an attacker-controlled JSON Schema, OpenAPI, YAML, JSON, Avro, Protobuf, or XSD schema. Specifically, if a property within the input schema contains a <code>&quot;default_factory&quot;</code> key, its value is interpolated verbatim as a raw Python expression into the generated <code>Field(default_factory=...)</code> or <code>field(default_factory=...)</code> call. This code executes at class-definition time when the generated Python module is imported by a consumer. No special CLI flags are required for exploitation, making any developer or CI pipeline processing untrusted schemas susceptible. The fix involves validating <code>default_factory</code> values to only accept <code>dict</code>, <code>list</code>, and <code>set</code>.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker crafts a malicious schema (e.g., JSON Schema, OpenAPI, YAML) containing a <code>&quot;default_factory&quot;</code> key with arbitrary Python code as its value.</li>
<li>A victim developer or CI pipeline uses <code>datamodel-code-generator</code> (versions 0.17.0 through 0.60.1) to generate Python data models from this attacker-controlled schema.</li>
<li>During code generation, the <code>datamodel-code-generator</code> parser (e.g., <code>jsonschema.py</code>) identifies the <code>&quot;default_factory&quot;</code> key.</li>
<li>The value associated with <code>&quot;default_factory&quot;</code> is retrieved from <code>self.extras</code> within the <code>JsonSchemaObject</code>.</li>
<li>When constructing the Python model (e.g., Pydantic v2, dataclass, msgspec), <code>datamodel-code-generator</code> interpolates the raw, unvalidated <code>default_factory</code> value directly into the generated Python code without sanitization.</li>
<li>The victim's Python application or environment imports the newly generated Python module.</li>
<li>Upon import, the interpolated malicious Python code embedded in the <code>default_factory</code> argument is executed at class-definition time within the importing process, leading to arbitrary code execution.</li>
<li>The attacker achieves their objective, such as filesystem reads (e.g., copying <code>/etc/passwd</code>), environment variable exfiltration, or secondary network calls.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>This vulnerability poses a significant supply chain risk to developers and CI pipelines. Any environment that uses <code>datamodel-code-generator</code> to process schemas not authored internally (e.g., third-party API specs, public schema registries, vendored files, remote introspection endpoints) is directly affected. Successful exploitation leads to arbitrary Python code execution within the importing process at module import time. This can result in data exfiltration, system compromise (e.g., filesystem read/write, network access), or further malicious activity on CI runners where build environments often have elevated privileges. While <code>typing.TypedDict</code> output models are not vulnerable, all other supported output model types, including Pydantic v2, dataclasses, and msgspec, are susceptible.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade <code>datamodel-code-generator</code> to version <code>0.60.2</code> or later immediately to patch CVE-2026-54653.</li>
<li>Review CI/CD pipelines and developer workstations to ensure all instances of <code>datamodel-code-generator</code> are updated.</li>
<li>Implement controls to validate or restrict the source of schemas used for code generation, especially those from external or untrusted origins.</li>
<li>Monitor for unexpected process execution or file system modifications originating from Python processes that have recently imported newly generated data models, particularly if untrusted schemas are processed.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>code-injection</category><category>supply-chain</category><category>developer-tools</category><category>python</category><category>rce</category><category>cve</category></item><item><title>datamodel-code-generator Vulnerable to SSRF Protection Bypass via DNS Rebinding</title><link>https://feed.craftedsignal.io/briefs/2026-07-datamodel-ssrf-bypass/</link><pubDate>Tue, 28 Jul 2026 21:49:12 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2026-07-datamodel-ssrf-bypass/</guid><description>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.</description><content:encoded><![CDATA[<p>The <code>datamodel-code-generator</code> Python library, specifically versions <code>0.62.0</code> 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 <code>httpx</code> 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., <code>127.0.0.1</code> or <code>169.254.169.254</code>) 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 <code>--url</code> argument or remote <code>$ref</code> references in schemas. The vulnerability is present in versions up to <code>0.62.0</code> and was fixed in version <code>0.63.0</code>.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker registers a domain name (e.g., <code>attacker.com</code>) and configures its DNS records with a very low Time-To-Live (TTL).</li>
<li>The attacker configures the domain to initially resolve to a public, internet-routable IP address.</li>
<li>The attacker influences a victim's <code>datamodel-code-generator</code> instance (e.g., in a CI pipeline or local development environment) to fetch a URL pointing to <code>http://attacker.com/schema.json</code> via the <code>--url</code> command-line argument or a remote <code>$ref</code> within a schema.</li>
<li>The <code>datamodel-code-generator</code>'s <code>_validate_url_for_fetch()</code> function performs the initial DNS resolution of <code>attacker.com</code> (resolution #1). The public IP passes the SSRF guard's check.</li>
<li>Between validation and connection, the attacker rapidly changes the DNS record for <code>attacker.com</code> to resolve to a private IP address (e.g., <code>127.0.0.1</code>, <code>169.254.169.254</code>, or another internal network address).</li>
<li>The <code>httpx.get()</code> function within <code>datamodel-code-generator</code> performs its own, independent DNS resolution for <code>attacker.com</code> (resolution #2). Due to the low TTL and attacker's control, this resolution now returns the private IP address.</li>
<li><code>httpx</code> connects to the private IP address, bypassing the initial validation and establishing an SSRF connection to an internal service or resource.</li>
<li>The attacker gains unauthorized access to internal HTTP services, reads cloud instance metadata credentials, or conducts internal network reconnaissance.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>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 <code>datamodel-code-generator</code> 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 <code>169.254.169.254</code>). 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 <code>datamodel-code-generator</code> implies a broad attack surface for organizations using the tool in potentially vulnerable configurations.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade <code>datamodel-code-generator</code> to version <code>0.63.0</code> or later immediately to remediate CVE-2026-55391.</li>
<li>Implement strict network egress filtering on systems running <code>datamodel-code-generator</code> to restrict outbound connections to only necessary and trusted external destinations, blocking access to private IP ranges, especially <code>169.254.169.254</code>.</li>
<li>Monitor DNS query logs for suspicious or rapid changes in IP resolution for external domains accessed by internal tools.</li>
<li>Avoid running <code>datamodel-code-generator</code> in environments where <code>--url</code> parameters or remote <code>$ref</code> references can be influenced by untrusted external input.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>ssrf</category><category>dns-rebinding</category><category>vulnerability</category><category>supply-chain</category><category>python</category></item></channel></rss>