VAITP Dataset

← Back to the dataset

CVE-2026-108382

Unsafe enum rendering allows code injection via crafted symbols in generated code.

  • CVSS 8.8
  • CWE-94
  • Input Validation and Sanitization
  • Local

dataclasses-avroschema generates Avro schemas from Python dataclasses, Pydantic models, and Faust Records and generates Python code from Avro schemas. From version 0.38.0 through 0.70.5, EnumRepresentation.render_symbols concatenates each schema-controlled enum symbol between double quotes in a generated enum assignment. When generator classes are used directly, a quote can terminate the string literal and inject arbitrary Python code into the enum class body, which executes when the generated module is imported. Version 0.70.6 fixes the vulnerability by escaping enum symbol values before rendering them.

CVSS base score
8.8
Published
2026-10-13
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
dataclasses-avroschema
Fixed by upgrading
Yes

Solution

Upgrade dataclasses‑avroschema to version 0.70.6 or later.

Vulnerable code sample

from dataclasses import dataclass
from enum import Enum
from dataclasses_avroschema import AvroModel, EnumRepresentation

# VULNERABLE: unsanitized enum symbol leads to code injection
def generate_enum_class(name: str, symbols):
    lines = ["class " + name + "(Enum):"]
    for sym in symbols:
        # directly embed symbol in string literal
        lines.append(f'    {sym} = "{sym}"')
    return "\n".join(lines)

# Example usage that would be vulnerable if symbols contain a quote
class ColorModel(AvroModel):
    class Config:
        enum_representation = EnumRepresentation.RENDER_SYMBOLS

    color: Enum = Enum('Color', ['RED', 'GREEN', 'BLUE'])

# Simulate code generation
enum_src = generate_enum_class("Color", ['RED', 'GREEN', 'BLUE'])
exec(enum_src)

Patched code sample

from dataclasses import dataclass
from enum import Enum
from dataclasses_avroschema import AvroModel, EnumRepresentation
import json

# FIX: escape enum symbols before rendering to prevent injection
def generate_enum_class(name: str, symbols):
    lines = ["class " + name + "(Enum):"]
    for sym in symbols:
        # safely embed escaped symbol using json.dumps (adds quotes)
        escaped = json.dumps(sym)[1:-1]  # strip outer quotes
        lines.append(f'    {sym} = "{escaped}"')
    return "\n".join(lines)

# Example usage after fix
class ColorModel(AvroModel):
    class Config:
        enum_representation = EnumRepresentation.RENDER_SYMBOLS

    color: Enum = Enum('Color', ['RED', 'GREEN', 'BLUE'])

# Simulate code generation
enum_src = generate_enum_class("Color", ['RED', 'GREEN', 'BLUE'])
exec(enum_src)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • fix: security patched (marcosschroh/dataclasses-avroschema)
    dataclasses_avroschema/exceptions.py, dataclasses_avroschema/model_generator/lang/python/avrodantic/avrodantic_model_generator.py, dataclasses_avroschema/model_generator/lang/python/avrodantic/avrodantic_model_generator.py · AvroDanticModelGenerator._resolve_type_from_metadata, dataclasses_avroschema/model_generator/lang/python/base.py, dataclasses_avroschema/model_generator/lang/python/base.py · BaseGenerator.parse_enum, dataclasses_avroschema/model_generator/lang/python/base.py · BaseGenerator.parse_fixed, dataclasses_avroschema/model_generator/lang/python/base.py · ClassRepresentation.render_docstring, dataclasses_avroschema/model_generator/lang/python/base.py · ClassRepresentation.render_metaclass, dataclasses_avroschema/model_generator/lang/python/base.py · EnumRepresentation.render_symbols, dataclasses_avroschema/model_generator/lang/python/base.py · FieldRepresentation.get_field_default, dataclasses_avroschema/model_generator/lang/python/pydantic/pydantic_model_generator.py, dataclasses_avroschema/model_generator/lang/python/pydantic/pydantic_model_generator.py · PydanticFieldRepresentation.add_field_properties and 2 more

Cite this entry

@misc{vaitp:cve2026108382,
  title        = {{Unsafe enum rendering allows code injection via crafted symbols in generated code.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-108382},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-108382/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.