CVE-2026-108378
Unescaped docstrings allow code injection via crafted schema docs.
- CVSS 8.8
- CWE-94
- Input Validation and Sanitization
- Remote
dataclasses-avroschema generates Avro schemas from Python dataclasses, Pydantic models, and Faust Records and generates Python code from Avro schemas. From version 0.40.0 through 0.70.5, ClassRepresentation.render_docstring copies a schema record's doc value into a generated triple-double-quoted class docstring without escaping quotes or backslashes. A crafted triple-quote sequence can close the docstring and inject statements into the generated class body, while a trailing backslash can escape the generated closing delimiter, allowing Python code execution during module import. Version 0.70.6 fixes the vulnerability by escaping quotes, backslashes, and unsafe control characters before rendering docstrings.
- CWE
- CWE-94
- 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
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- dataclasses-avroschema
- Fixed by upgrading
- Yes
Solution
Upgrade to dataclasses‑avroschema v0.70.6 (or later).
Vulnerable code sample
import json
class ClassRepresentation:
def __init__(self, schema: dict):
self.schema = schema
self.docstring = ""
def render_docstring(self):
# VULNERABLE: directly injects schema doc into triple-quoted string
doc = self.schema.get("doc", "")
self.docstring = f'''"""{
doc
}"""'''
def generate_class(self):
self.render_docstring()
class_code = f'''
{self.docstring}
class Generated:
pass
'''
return class_code
# Example usage (not executed)
vuln_schema = {
"type": "record",
"name": "Test",
"doc": 'Example doc with triple quotes """ and a backslash \\'
}
vuln_repr = ClassRepresentation(vuln_schema)
vuln_code = vuln_repr.generate_class()Patched code sample
import json
import re
class ClassRepresentation:
def __init__(self, schema: dict):
self.schema = schema
self.docstring = ""
def _escape_doc(self, doc: str) -> str:
# FIX: escape triple quotes, backslashes, and control chars
doc = doc.replace('\\', '\\\\')
doc = doc.replace('"""', '\\"""')
# Remove other unsafe control characters (e.g., newline)
doc = re.sub(r'[\x00-\x1f]', '', doc)
return doc
def render_docstring(self):
doc = self.schema.get("doc", "")
safe_doc = self._escape_doc(doc)
self.docstring = f'''"""{
safe_doc
}"""'''
def generate_class(self):
self.render_docstring()
class_code = f'''
{self.docstring}
class Generated:
pass
'''
return class_code
# Example usage (not executed)
fixed_schema = {
"type": "record",
"name": "Test",
"doc": 'Example doc with triple quotes """ and a backslash \\'
}
fixed_repr = ClassRepresentation(fixed_schema)
fixed_code = fixed_repr.generate_class()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_propertiesand 2 more
Cite this entry
@misc{vaitp:cve2026108378,
title = {{Unescaped docstrings allow code injection via crafted schema docs.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-108378},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-108378/}}
}
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 ::
