GHSA-8m8r-38jm-f355: `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data
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
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.
- Low exploitation riskCVE-2026-546560.15% 30-day exploitation probability — currently an unlikely target, but scores change as exploit code circulates. Riskier than 5% of all scored CVEs.
Referenced CVEs
| CVE | CSIRTS overview | External |
|---|---|---|
| CVE-2026-54656 | coverage & exploitation status | NVD · CVE.org |
Same CVEs, other sources
How other CERTs, PSIRTs and databases cover the vulnerabilities in this advisory.
More from GitHub Security Advisories
- mediumGHSA-jr6p-8pjj-mfx6: Capsule has an incomplete fix of CVE-2026-22872: TenantResource RawItems and Generators s…2026-07-31
- mediumGHSA-68cj-mvg9-rgm2: Capsule: CapsuleConfiguration NodeMetadata regex fields lack webhook validation, allowing…2026-07-31
- mediumGHSA-ff84-5f28-78qj: re2: Out-of-bounds heap read in `exec`/`test`/`match` via attacker-influenced `lastIndex`…2026-07-31
- mediumGHSA-6hxr-mr5r-9836: re2: Global `String.prototype.match` with an empty-matchable pattern never advances → inf…2026-07-31
- mediumGHSA-x83g-979r-f5fh: Sylius Mollie Plugin has unauthenticated IDOR that leaks order token and customer PII2026-07-31