CVE-2026-54656: `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data
When the Pydantic v2 output mode is in use, datamodel-code-generator reads a validators array from each model entry in the --extra-template-data file and synthesises a Pydantic @field_validator(...) decorator from each entry. The field names and the validator mode are interpolated into the decorator call wrapped in unescaped single quotes. A value containing ' breaks out of the string literal, letting an attacker emit an arbitrary positional Python expression into the decorator. The expression is evaluated at class-definition time, i.e. the moment the developer imports the generated module. This is the same trust model as the recently-published GHSA-wjv6-jcfj-mf9r (extras-file comment injection) but the impact is full RCE rather than a docstring leak.
References
- github.com/advisories/GHSA-8m8r-38jm-f355
- github.com/koxudaxi/datamodel-code-generator/commit/a43d02906111a2fdcaf13ee5b62eb2da85376f19
- github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2
- github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-8m8r-38jm-f355
- nvd.nist.gov/vuln/detail/CVE-2026-54656
Code Behaviors & Features
Detect and mitigate CVE-2026-54656 with GitLab Dependency Scanning
Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →