<?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 (&gt;= 0.17.0, &lt;= 0.60.1) - CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/datamodel-code-generator--0.17.0--0.60.1/</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/products/datamodel-code-generator--0.17.0--0.60.1/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></channel></rss>