CVE-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
⚡ Watch CVE-2026-54656
Get an email if CVE-2026-54656 is added to CISA KEV, gains public exploit code, or a new advisory cites it — max one per day, one-click unsubscribe.
Exploitation outlook
- Low exploitation risk0.15% 30-day exploitation probability — currently an unlikely target, but scores change as exploit code circulates. Riskier than 5% of all EPSS-scored CVEs.
Advisory coverage (2)
External references
Embed the live status
— this badge updates automatically when the KEV or exploit status changes. How to embed it →
[](https://www.csirts.com/cve/CVE-2026-54656)