datamodel-code-generator vulnerable to code execution on import via x-python-type JSON-Schema extension in datamodel-code-generator
CVE-2026-54655GHSA-m34r-v34r-rf9q
What to do
Vendor fix available. Upgrade each affected package to the fixed version on its release line (datamodel-code-generator 0.60.2), redeploy, then verify what is actually installed.
This page has no inventory attached, so it cannot say whether you are affected. A vendor fix is not proof that your deployment is fixed.
Affected packages
- Affected
- >= 0.51.0, <= 0.60.1
- Fixed in
- 0.60.2
Sources
- GitHub Advisory Database and maintainer security advisories on GitHub
GitHub-reviewed advisory GHSA-m34r-v34r-rf9q lists affected ranges: PyPI datamodel-code-generator >=0.51.0 <=0.60.1
VerifiedObserved Structured GitHub Advisory Database record (type=reviewed) from the GitHub REST API.
Severity and exploitation
- Exploitation
- No confirmed exploitation recorded. Patch Next marks exploitation only from CISA KEV.
- CVSS
- 7.8 · CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- EPSS
- CVE-2026-54655: 0.21% estimated exploitation activity in the next 30 days; percentile 11.25 (FIRST EPSS, 2026-11-03). This is a model estimate, not proof of exploitation or customer exposure.
Source description
As published by the source; long descriptions are shortened.
Summary datamodel-code-generator honours a custom x-python-type JSON-Schema extension that lets a schema author override the generated Python type for a field. The value is forwarded verbatim into the generated Python source as the field annotation, with a single sanitisation pass that is trivial to bypass. An attacker who controls a JSON Schema fed to datamodel-codegen can therefore embed an arbitrary Python statement in the generated module, which executes at class-definition time the moment the developer imports the file. No --extra-template-data and no special flags are required; the vulnerable code is reachable with default settings. Details Sink: src/datamodelcodegenerator/parser/jsonschema.py, getpythontypeoverride (lines 2055–2096, at tag 0.60.1 / commit a321547e): DataType.type flows unescaped into {{ field.typehint }} in every model template (model/template/pydanticv2/BaseModel.jinja2, model/template/dataclass.jinja2, model/template/TypedDictClass.jinja2,…
Dates and revisions
- Published by the source
- Last modified by the source
- Source last checked
- Revision 1 · created ·
Published from ghsa record GHSA-m34r-v34r-rf9q
Agent brief
Preview the exact text before you copy it. Commands are read-only suggestions; review them before running anything.
# Patch Next advisory brief: CVE-2026-54655 Advisory: `datamodel-code-generator` vulnerable to code execution on import via `x-python-type` JSON-Schema extension in datamodel-code-generator IDs: CVE-2026-54655, GHSA-m34r-v34r-rf9q Record: https://patchnext.com/advisories/cve-2026-54655 (revision 1, source checked 26 Oct 2026, 13:50 UTC) Inventory: none attached. This brief comes from a public page and does not say whether any deployment is affected. Severity: High (CVSS 7.8) Exploitation: no confirmed exploitation recorded. Patch Next confirms exploitation only from CISA KEV. Vendor response: Vendor fix available; fixed versions by package: datamodel-code-generator 0.60.2. A vendor fix does not mean a deployment is fixed. ## Affected components - PyPI datamodel-code-generator: affected >= 0.51.0, <= 0.60.1; fixed in 0.60.2 ## Suggested inspection (read-only) - `python -m pip show datamodel-code-generator`: prints the installed version. Run with the environment that serves production active. ## Supported action Upgrade each affected component to a fixed version on its release line. For a transitive dependency, upgrade the parent package or add an override or constraint, then regenerate the lockfile. Redeploy every environment that ran an affected version. ## Required regression checks - Run the test suite and a production build. - Exercise the features that depend on datamodel-code-generator. - Repeat the inspection and confirm that only fixed versions remain installed. ## Rollback considerations - Keep the previous lockfile and deployment artifact. Rolling back reinstates the vulnerable version, so apply any documented mitigation while you fix forward. ## Unresolved questions - Which deployments run an affected version? - Exploitation status can change. Check again before lowering the priority. - Mark the work resolved only after the fixed version is verified in production. ## Sources - Verified: https://github.com/advisories/GHSA-m34r-v34r-rf9q (GitHub-reviewed advisory GHSA-m34r-v34r-rf9q lists affected ranges: PyPI datamodel-code-generator >=0.51.0 <=0.60.1) Commands are suggestions: review each one before running it.
Loading voting…