/

CVE-2026-108380

Severity:

HIGH RISK

(8.8)

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

CVE-2026-108380

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Python 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 generate Python models from Avro schemas, but certain documentation values are inserted into generated Pydantic field definitions without escaping. If an attacker can influence a schema field's documentation and trigger model generation, injected expressions may execute as Python code during class definition.

dataclasses-avroschema can generate Python models from Avro schemas, but certain documentation values are inserted into generated Pydantic field definitions without escaping. If an attacker can influence a schema field's documentation and trigger model generation, injected expressions may execute as Python code during class definition.

Affected context

The vulnerability occurs in environments that use dataclasses-avroschema to generate Pydantic or AvroDantic models from Avro schemas. It becomes risky when schema documentation values are attacker-controlled or insufficiently trusted and are rendered directly into generated Python source without appropriate escaping.

The vulnerability occurs in environments that use dataclasses-avroschema to generate Pydantic or AvroDantic models from Avro schemas. It becomes risky when schema documentation values are attacker-controlled or insufficiently trusted and are rendered directly into generated Python source without appropriate escaping.

Exploit preconditions

  • Attack surface: Avro schema processing and generated Pydantic or AvroDantic model creation
  • Required access: Ability to supply or modify an Avro schema field documentation value
  • Trigger point: Generation and definition of the resulting Python model class
  • Why exploitation is possible: The documentation value is inserted into a generated string literal without escaping, allowing crafted content to alter the generated expression
  • Attack surface: Avro schema processing and generated Pydantic or AvroDantic model creation
  • Required access: Ability to supply or modify an Avro schema field documentation value
  • Trigger point: Generation and definition of the resulting Python model class
  • Why exploitation is possible: The documentation value is inserted into a generated string literal without escaping, allowing crafted content to alter the generated expression

Why this happens

The underlying bug is an output-encoding failure in a source-code generation path. A schema field's doc value is placed inside a generated pydantic.Field description string without escaping embedded quotes or other syntax-significant characters. This allows data intended to remain a string literal to change the structure of generated Python code, matching CWE-94: Improper Control of Generation of Code ('Code Injection').

The underlying bug is an output-encoding failure in a source-code generation path. A schema field's doc value is placed inside a generated pydantic.Field description string without escaping embedded quotes or other syntax-significant characters. This allows data intended to remain a string literal to change the structure of generated Python code, matching CWE-94: Improper Control of Generation of Code ('Code Injection').

Potential impact

  • An attacker may execute arbitrary Python expressions in the model-generation process.
  • Generated application code may be compromised before normal validation occurs.
  • Credentials, environment variables, or local files could be exposed.
  • The affected process could be used to modify data or access connected services.
  • A compromised build or generation pipeline could enable broader supply-chain impact.
  • An attacker may execute arbitrary Python expressions in the model-generation process.
  • Generated application code may be compromised before normal validation occurs.
  • Credentials, environment variables, or local files could be exposed.
  • The affected process could be used to modify data or access connected services.
  • A compromised build or generation pipeline could enable broader supply-chain impact.

General mitigation guidance

Mitigation generally focuses on treating schema metadata as untrusted data throughout code-generation workflows.

Common defensive patterns include:

  • Escaping documentation and metadata values according to the target Python syntax before rendering source code.
  • Preferably constructing model objects through safe APIs or structured representations rather than concatenating source-code fragments.
  • Applying strict schema validation and limiting accepted metadata formats.
  • Separating trusted generation inputs from user-controlled schemas and reducing input trust wherever possible.
  • Running generation processes with least-privilege permissions, restricted filesystem access, and limited network reachability.
  • Reviewing generated source before execution and avoiding automatic execution of unverified generated code.

Mitigation generally focuses on treating schema metadata as untrusted data throughout code-generation workflows.

Common defensive patterns include:

  • Escaping documentation and metadata values according to the target Python syntax before rendering source code.
  • Preferably constructing model objects through safe APIs or structured representations rather than concatenating source-code fragments.
  • Applying strict schema validation and limiting accepted metadata formats.
  • Separating trusted generation inputs from user-controlled schemas and reducing input trust wherever possible.
  • Running generation processes with least-privilege permissions, restricted filesystem access, and limited network reachability.
  • Reviewing generated source before execution and avoiding automatic execution of unverified generated code.

How teams detect issues like this

Detection can include static analysis for string interpolation or concatenation into Python source, especially where schema fields are inserted into quoted literals. Code review should examine escaping boundaries, generated Field arguments, and any path that evaluates or imports generated classes. Policy checks can require structured code-generation APIs, schema provenance validation, and tests containing quotes and syntax-significant metadata. Automated review tools may help identify unsanitized data flowing into executable source-generation sinks.

Detection can include static analysis for string interpolation or concatenation into Python source, especially where schema fields are inserted into quoted literals. Code review should examine escaping boundaries, generated Field arguments, and any path that evaluates or imports generated classes. Policy checks can require structured code-generation APIs, schema provenance validation, and tests containing quotes and syntax-significant metadata. Automated review tools may help identify unsanitized data flowing into executable source-generation sinks.

Sources

SourceLink
github.comgithub.com/marcosschroh/dataclasses-avroschema/commit/429f3d705d2d04c0c65e2ef832daed5ff91318fc
github.comgithub.com/marcosschroh/dataclasses-avroschema/pull/843
github.comgithub.com/marcosschroh/dataclasses-avroschema/releases/tag/0.70.6
github.comgithub.com/marcosschroh/dataclasses-avroschema/security/advisories/GHSA-g7p7-mgvm-jw7p

Frequently asked

questions

It can be exploitable remotely when an application accepts attacker-controlled Avro schemas or retrieves schemas from an untrusted source and automatically generates models. In other deployments, exploitation may require local access to generation inputs or a compromised schema repository.

The attacker needs a way to influence a schema field's documentation value and cause the affected Pydantic or AvroDantic generation path to run. Direct access to the host is not necessarily required if schemas are accepted through an exposed service or pipeline.

Treat schema metadata strictly as data: use structured model-construction APIs where possible, and apply correct Python-source escaping when source generation is unavoidable. Generated code should not be executed unless its inputs and output have been verified.

Add source-generation security reviews, fuzz metadata fields with quotes and escape characters, validate schema provenance, and enforce least privilege for generation workers. Static analysis and CI policy checks can also flag untrusted data flowing into executable code.

It can be exploitable remotely when an application accepts attacker-controlled Avro schemas or retrieves schemas from an untrusted source and automatically generates models. In other deployments, exploitation may require local access to generation inputs or a compromised schema repository.

The attacker needs a way to influence a schema field's documentation value and cause the affected Pydantic or AvroDantic generation path to run. Direct access to the host is not necessarily required if schemas are accepted through an exposed service or pipeline.

Treat schema metadata strictly as data: use structured model-construction APIs where possible, and apply correct Python-source escaping when source generation is unavoidable. Generated code should not be executed unless its inputs and output have been verified.

Add source-generation security reviews, fuzz metadata fields with quotes and escape characters, validate schema provenance, and enforce least privilege for generation workers. Static analysis and CI policy checks can also flag untrusted data flowing into executable code.

Find out what's already
exploitable in your codebase.