/

CVE-2026-108378

Severity:

HIGH RISK

(8.8)

Code Injection (CWE-94) in dataclasses-avroschema Generator

CVE-2026-108378

Awaiting Analysis

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

dataclasses-avroschema can copy attacker-controlled Avro record documentation into generated Python class docstrings without escaping special characters. A crafted schema may therefore inject Python statements that execute when the generated module is imported, particularly when untrusted schemas are processed or distributed.

dataclasses-avroschema can copy attacker-controlled Avro record documentation into generated Python class docstrings without escaping special characters. A crafted schema may therefore inject Python statements that execute when the generated module is imported, particularly when untrusted schemas are processed or distributed.

Affected context

The vulnerability occurs in deployments that use dataclasses-avroschema to generate Python code from Avro schemas and then import or execute that generated code. It is relevant when schema documentation fields can be influenced by an untrusted user, external repository, build artifact, or other source outside the application's security boundary.

The vulnerability occurs in deployments that use dataclasses-avroschema to generate Python code from Avro schemas and then import or execute that generated code. It is relevant when schema documentation fields can be influenced by an untrusted user, external repository, build artifact, or other source outside the application's security boundary.

Exploit preconditions

  • Attack surface: Avro schema processing and Python source-code generation
  • Required access: Ability to supply or modify an Avro schema record's doc value
  • Trigger point: Import or execution of the generated Python module
  • Why exploitation is possible: Documentation text is inserted into a generated triple-quoted Python string without safely escaping quotes, backslashes, and unsafe control characters
  • Attack surface: Avro schema processing and Python source-code generation
  • Required access: Ability to supply or modify an Avro schema record's doc value
  • Trigger point: Import or execution of the generated Python module
  • Why exploitation is possible: Documentation text is inserted into a generated triple-quoted Python string without safely escaping quotes, backslashes, and unsafe control characters

Why this happens

The vulnerable code treats schema documentation as inert text while rendering it directly into Python source code. Because delimiter characters and escape sequences are not encoded for the target language, crafted documentation can terminate the generated docstring and introduce additional statements into the class body.

This behavior maps to CWE-94: Improper Control of Generation of Code, where externally influenced data is incorporated into generated source without adequate contextual escaping or structural separation.

The vulnerable code treats schema documentation as inert text while rendering it directly into Python source code. Because delimiter characters and escape sequences are not encoded for the target language, crafted documentation can terminate the generated docstring and introduce additional statements into the class body.

This behavior maps to CWE-94: Improper Control of Generation of Code, where externally influenced data is incorporated into generated source without adequate contextual escaping or structural separation.

Potential impact

  • Execution of attacker-selected Python code during module import
  • Compromise of the application or build environment
  • Exposure or modification of accessible secrets and data
  • Supply-chain contamination through malicious generated artifacts
  • Persistence or lateral movement within the affected runtime environment
  • Execution of attacker-selected Python code during module import
  • Compromise of the application or build environment
  • Exposure or modification of accessible secrets and data
  • Supply-chain contamination through malicious generated artifacts
  • Persistence or lateral movement within the affected runtime environment

General mitigation guidance

Mitigation generally focuses on separating data from generated source code and applying context-appropriate encoding before rendering.

Common defensive patterns include:

  • Escaping quotes, backslashes, and unsafe control characters for Python string contexts
  • Using structured code-generation APIs or templates that preserve data boundaries
  • Treating external Avro schemas as untrusted input
  • Reviewing generated artifacts before import or distribution
  • Restricting the privileges and filesystem access of code-generation and import processes
  • Avoiding automatic execution of generated code from untrusted sources

Mitigation generally focuses on separating data from generated source code and applying context-appropriate encoding before rendering.

Common defensive patterns include:

  • Escaping quotes, backslashes, and unsafe control characters for Python string contexts
  • Using structured code-generation APIs or templates that preserve data boundaries
  • Treating external Avro schemas as untrusted input
  • Reviewing generated artifacts before import or distribution
  • Restricting the privileges and filesystem access of code-generation and import processes
  • Avoiding automatic execution of generated code from untrusted sources

How teams detect issues like this

Organizations can identify this class of issue through:

  • Static analysis for direct interpolation of schema fields into Python source
  • Code review checks for generated string literals built from external metadata
  • Tests using quotes, backslashes, control characters, and delimiter sequences in schema documentation
  • Build policies that inspect or prohibit unreviewed generated source artifacts
  • Runtime monitoring for unexpected child processes, filesystem changes, or network activity during module import

Automated security and code-quality review tools may help identify unsafe code-generation patterns, but generated output should also be inspected because source-level checks may miss template-specific escaping failures.

Organizations can identify this class of issue through:

  • Static analysis for direct interpolation of schema fields into Python source
  • Code review checks for generated string literals built from external metadata
  • Tests using quotes, backslashes, control characters, and delimiter sequences in schema documentation
  • Build policies that inspect or prohibit unreviewed generated source artifacts
  • Runtime monitoring for unexpected child processes, filesystem changes, or network activity during module import

Automated security and code-quality review tools may help identify unsafe code-generation patterns, but generated output should also be inspected because source-level checks may miss template-specific escaping failures.

Sources

SourceLink
github.comgithub.com/marcosschroh/dataclasses-avroschema/commit/429f3d705d2d04c0c65e2ef832daed5ff91318fc
github.comgithub.com/marcosschroh/dataclasses-avroschema/releases/tag/0.70.6
github.comgithub.com/marcosschroh/dataclasses-avroschema/security/advisories/GHSA-ff3j-hw44-6vx4

Frequently asked

questions

It can be exploitable through a remote or supply-chain path when an attacker can provide or modify an Avro schema and a downstream process imports the generated Python code. It is not necessarily directly reachable over a network without such a schema ingestion path.

The attacker generally needs control over, or the ability to influence, a schema record's documentation value and must have that schema processed into Python code that is subsequently imported or executed.

Keep schema documentation as data and apply complete Python-string escaping before rendering it into source. Structured generation approaches that avoid manual source interpolation provide an additional safety boundary.

Treat all schema metadata as untrusted, test generated output with adversarial delimiter and escape characters, review generated artifacts, and run generation or import workflows with least privilege.

It can be exploitable through a remote or supply-chain path when an attacker can provide or modify an Avro schema and a downstream process imports the generated Python code. It is not necessarily directly reachable over a network without such a schema ingestion path.

The attacker generally needs control over, or the ability to influence, a schema record's documentation value and must have that schema processed into Python code that is subsequently imported or executed.

Keep schema documentation as data and apply complete Python-string escaping before rendering it into source. Structured generation approaches that avoid manual source interpolation provide an additional safety boundary.

Treat all schema metadata as untrusted, test generated output with adversarial delimiter and escape characters, review generated artifacts, and run generation or import workflows with least privilege.

Find out what's already
exploitable in your codebase.