vulnerability / NVI-00015031 / Revision 1
`datamodel-code-generator` vulnerable to code injection via unescaped carriage return in GraphQL Union description
GitHub lists this reviewed advisory for datamodel-code-generator. Published version ranges and source prerequisites are shown below; this is not an inspection of a visitor’s application.
This report has not inspected your inventory, configuration, deployed build, reachability or evidence. A catalog listing and a severity score do not establish exposure or compromise.
01 / Meaning
Why it matters
Published affected context helps an owner decide what evidence to gather. This report has not examined your application.
7.8 high
GitHub source severity; exploitability and local consequence require separate evidence.
As of · GitHub Advisory Database
02 / Applicability
The affected context
Affected versions, configuration prerequisites and known exclusions are public. Confirm each one against the deployed service.
datamodel-code-generator
source listed>= 0.25.0, < 0.60.1
### Summary `datamodel-code-generator` is vulnerable to code injection when generating Python models from an attacker-controlled GraphQL schema. A description on a Union type, written in the regular-string form (`"..."`) with a literal `\r` escape, is rendered into a Python `#` comment by a Jinja2 filter that handles only `\n`. Python's tokenizer treats a bare CR as a physical-line terminator, so the comment ends at the `\r` and the text after it is parsed as module-level Python. The injected code executes at `import` time of the generated `.py`, in the context of any consumer that imports the model. No special CLI flags are required. This affects versions `>=0.25.0, <0.60.1` and is fixed in `0.60.1`. ### Details The vulnerable output was generated by the GraphQL Union templates: - `src/datamodel_code_generator/model/template/UnionTypeStatement.jinja2` - `src/datamodel_code_generator/model/template/UnionTypeAliasAnnotation.jinja2` - `src/datamodel_code_generator/model/template/UnionTypeAliasType.jinja2` Before `0.60.1`, Union descriptions were rendered as Python comments using logic equivalent to `# {{ description | replace('\n', '\n# ') }}`. The Jinja2 `replace` filter hand
03 / Response
What to do next
- investigate
Identify the exact component and deployed version, examine the linked publisher’s conditions, and retain evidence of any mitigation.
Confirm current vendor support, compatibility and deployment evidence. This report has not tested a fix in your system. GitHub Advisory Database
A fixed release is not deployment evidence.
Check current vendor support and compatibility. After making a change, verify the deployed build and relevant runtime conditions. Keep the evidence, owner and time. An updated lockfile alone does not prove what is running.
04 / Limits
What this report cannot establish
- Customer inventory, deployment, reachability and exploitation have not been inspected.
05 / Provenance
Sources you can inspect
Each assertion retains its source. Mirrored records may repeat one underlying publisher; additional links are not independent corroboration.
- GHSA-j884-q54q-mmx3 ↗
GitHub Advisory Database · vendor advisory
Observed . GitHub Advisory Database; CC-BY-4.0. Each advisory links its original attribution. Null normalizes fields.
Public revision history
Only published revisions appear here. Routine fetches do not create a material-change event.
- Revision 1 ·
First indexed by Null; source disclosure date is shown separately.