CSIRTS // UNIFIED SECURITY ADVISORY FEEDSYS ● ONLINE · POWERED BY INTELFUSIONS.COM

GHSA-8m8r-38jm-f355: `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data

highCVSS 7.8CVE-2026-54656
Summary 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. Details Sink: src/datamodel_code_generator/model/pydantic_v2/base_model.py, _process_validators (lines 405–449, at tag 0.60.1 / commit a321547e): def _process_validators(self) -> None: validators = self.extra_template_data.get("validators") if not validators: return ... for validator in validators: fields = validator.get("fields") or [validator.get("field")] fields = [f for f in fields if f] if not fields: continue function_path: str = validator["function"] function_name = function_path.rsplit(".", 1)[-1] mode = validator.get("mode", "after") fields_str = ", ".join(f"'{f}'" for f in fields) # (A) UNESCAPED ... mode_str = f"mode='{mode}'" # (B) UNESCAPED prepared_validators.append({ "fields_str": fields_str, "mode_str": mode_str, "method_name": method_name, "function_name": function_name, "mode": mode, }) self._additional_imports.append(Import.from_full_path(function_path)) # (C) The strings from (A) and (B) flow verbatim into src/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2: @field_validator({{ v.fields_str }}, {{ v.mode_str }}) There is no repr() call, no identifier check, and no quote-escaping. Secondary sink at (C): Import.from_full_path(function_path) splits on the last . a

Details

Source
GitHub Security Advisories (INTL · database · site)
Severity
high — CVSS 7.8
Published
2026-07-28
Last updated
2026-07-28
Exploitation
Not in CISA KEV at last sync

Original advisory: https://github.com/advisories/GHSA-8m8r-38jm-f355

Exploitation outlook

EPSS (FIRST.org) estimates each CVE’s probability of exploitation in the next 30 days — here is the CSIRTS.com read on those numbers.

Referenced CVEs

CVECSIRTS overviewExternal
CVE-2026-54656coverage & exploitation statusNVD · CVE.org

Same CVEs, other sources

How other CERTs, PSIRTs and databases cover the vulnerabilities in this advisory.

More from GitHub Security Advisories