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-54656

CVE-2026-54656: Arbitrary Code Execution in datamodel-code-generator via Unescaped Validator Configurations

Alon Barad
Alon Barad
Software Engineer

Jul 29, 2026·6 min read·31 visits

Executive Summary (TL;DR)

Unescaped string formatting in Pydantic v2 validator generation enables arbitrary code execution at module import time when processing malicious configurations.

CVE-2026-54656 is a high-severity arbitrary code execution vulnerability in the koxudaxi/datamodel-code-generator Python package. When processing validator metadata from external configuration files passed via the --extra-template-data argument, the code generator performs unescaped string interpolation into Pydantic v2 @field_validator decorators. This allows local attackers to construct malicious configuration files that inject arbitrary Python statements into generated models, executing code upon downstream import. This vulnerability has been resolved in version 0.60.2.

Vulnerability Overview

CVE-2026-54656 is a high-severity code injection vulnerability (classified under CWE-94) in the Python library datamodel-code-generator. The package is widely utilized to compile raw schemas—such as OpenAPI specifications, JSON Schema definitions, and GraphQL configurations—into clean Python classes, primarily targeting the Pydantic data validation framework. The vulnerability is situated within the library's Pydantic v2 code generation module, specifically involving the processing of user-defined field validation rules.\n\nThe attack surface is exposed when the code generator processes supplemental field-level validation settings supplied via the --extra-template-data command-line argument. This argument accepts custom metadata formats containing validator parameters. If an attacker can control or supply a maliciously prepared configuration file, they can control the inputs evaluated during code emission.\n\nBecause the target platform lacks robust validation or escaping on these properties, arbitrary Python payloads can be injected directly into the structure of generated files. This architectural vulnerability means that code execution occurs automatically as soon as any downstream system imports or loads the newly generated Python modules. The flaw represents a substantial threat to automated build systems, continuous integration (CI) environments, and developer workstations that programmatically process untrusted schemas.

Root Cause Analysis

The root cause of CVE-2026-54656 resides in src/datamodel_code_generator/model/pydantic_v2/base_model.py within the _process_validators() method. This method is designed to parse customized validation settings under the validators block of the configuration mapping. It extracts metadata keys such as fields, field, function, and mode to build lists of validation instructions that are subsequently passed to a Jinja2 template representing Pydantic @field_validator class decorators.\n\nDuring processing, the method evaluates the fields list and constructs a string representation (fields_str) using a list comprehension over an f-string: fields_str = ", ".join(f"'{f}'" for f in fields). The application assumes that input values are basic string field identifiers, wrapping each in single quotes without any character validation or sanitization. Similarly, the validator execution mode is formatted directly via mode_str = f"mode='{mode}'" without verification against permitted Pydantic validation phases.\n\nThis implementation creates a classic code generation escape. If a string within the fields list or mode contains a single quote character ('), the literal boundary of the Python string is terminated inside the generated code. A comma can then be appended to introduce new function parameters, or arbitrary Python expressions can be written to execute payload logic directly within the decorator's argument evaluation context.

Code Analysis

The vulnerable implementation in the _process_validators() function performs string joining via f-strings. Consider the key section of the vulnerable codebase:\n\npython\n# Vulnerable code block in base_model.py\ndef _process_validators(self) -> None:\n validators = self.extra_template_data.get(\"validators\")\n if not validators:\n return\n ...\n for validator in validators:\n fields = validator.get(\"fields\")\n # Unsafe f-string join without escaping\n fields_str = \", \".join(f\"'{f}'\" for f in fields)\n \n # Unsafe mode construct\n mode_str = f\"mode='{mode}'\"\n ...\n\n\nThe Jinja2 template renders these properties directly inside the class definition scope: @field_validator({{ fields_str }}, {{ mode_str }}). This direct inclusion permits the embedding of sub-expressions inside the decorator statement.\n\nTo remediate this issue, the maintainers implemented a multi-stage defensive strategy in commit a43d02906111a2fdcaf13ee5b62eb2da85376f19. First, they integrated a validation function normalize_validators() to parse inputs against structured schema models. Second, they replaced raw f-string interpolation with safe serialization using repr() and Python's string representation formats:\n\npython\n# Patched code block in base_model.py\n# The input data is processed through strong schema enforcement models\nfrom datamodel_code_generator.validators import normalize_validators\n\ndef _process_validators(self) -> None:\n self.extra_template_data.pop(\"prepared_validators\", None)\n validators = self.extra_template_data.get(\"validators\")\n if not validators:\n return\n\n # Enforce type, structural and identifier validation rules\n try:\n validators = normalize_validators(validators)\n except ValidationError as e:\n raise Error(f\"Invalid validators configuration: {format_validation_error(e)}\") from e\n ...\n for validator in validators:\n ...\n # Refactored to utilize safe string representation serializing\n fields_str = \", \".join(repr(f) for f in fields)\n \n # Uses Python format specifier '!r' which acts as repr()\n mode_str = f\"mode={mode!r}\"\n ...\n\n\nThis structural patch prevents injection. Any single quotes contained within the parameter values are correctly escaped as \\' during repr() evaluation, neutralizing the string breakout vector.

Exploitation Methodology

Exploitation of CVE-2026-54656 is local but can be weaponized in automated pipelines or client-side execution contexts. To trigger the flaw, an attacker must supply a malicious JSON or YAML configuration file via the --extra-template-data CLI parameter. There are three primary avenues for injection: field-level breakout, validation mode injection, and import-level injection.\n\nIn a field breakout scenario, an attacker modifies the configuration structure to inject Python execution primitives inside the string boundaries. An input structure targeting the field parameter might resemble the following:\n\njson\n{\n \"User\": {\n \"validators\": [\n {\n \"field\": \"name', __import__('os').system('touch /tmp/pwned'), 'email\",\n \"function\": \"myapp.validators.validate_name\"\n }\n ]\n }\n}\n\n\nDuring compilation, the generator writes the following line to the output Python model: @field_validator('name', __import__('os').system('touch /tmp/pwned'), 'email', mode='after'). When this generated file is loaded downstream (such as by an import statement or a test runner), the Python interpreter executes the __import__('os').system(...) command during module initialization, culminating in arbitrary command execution on the host environment.

Impact Assessment

The security impact of CVE-2026-54656 is assessed as high, with a CVSS v3.1 base score of 7.8 (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H). The local attack vector requires that a user or an automated agent execute the generator with a malicious input file and subsequently load the output Python module.\n\nBecause the payload executes at module-definition time upon import, it inherits the execution context and permissions of the executing process. This allows for compromise of confidentiality, integrity, and availability. In typical DevOps pipelines, the importing application may run with elevated privileges or hold environment secrets (such as API keys, cloud credentials, or database connection strings) that can be readily exfiltrated by a payload.\n\nWhile this CVE is not currently active in CISA's Known Exploited Vulnerabilities (KEV) catalog, the ease with which proof-of-concept payloads can be generated makes it a high risk for build pipelines processing third-party configurations.

Remediation & Patch Analysis

The recommended remediation is to upgrade datamodel-code-generator to version 0.60.2 or later. This release enforces a rigid validation schema, requiring that validator modes conform to Pydantic-approved constants (before, after, wrap, plain) and verifying that target fields are valid Python identifiers.\n\nIf immediate software upgrade is not feasible, operational environments should apply strict input filtering on configuration files before ingestion. Implement schema checkers to verify that all elements under validators are clean alphanumeric sequences, specifically rejecting any files containing control characters, semicolons, or single quotes.\n\nAdditionally, isolate automated build processes that utilize datamodel-code-generator within containerized sandboxes. Restrict the network egress of these environments during runtime to prevent exfiltration of credentials if an injection is successfully processed.

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

Affected Versions Detail

Product
Affected Versions
Fixed Version
datamodel-code-generator
koxudaxi
>= 0.52.1, < 0.60.20.60.2
AttributeDetail
CWE IDCWE-94
Attack VectorLocal
CVSS v3.17.8 (High)
Exploit Statuspoc
ImpactArbitrary Code Execution
Affected Range>= 0.52.1, < 0.60.2
Patched 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 software constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended code segment when it is sent to a downstream component.

References & Sources

  • [1]NVD - CVE-2026-54656
  • [2]GitHub Security Advisory GHSA-8m8r-38jm-f355
  • [3]datamodel-code-generator v0.60.2 Release Notes

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 6 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 8 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 9 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 10 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 11 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
10 views•5 min read
•about 12 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