CVE-2026-108381: dataclasses-avroschema pydantic-class metadata allows code injection in generated annotations
dataclasses-avroschema generates Avro schemas from Python dataclasses, Pydantic models, and Faust Records and generates Python code from Avro schemas. From version 0.44.0 through 0.70.5, the Pydantic and AvroDantic model generators insert a schema field's pydantic-class value after pydantic. in a generated field annotation without safely restricting the expression. Because annotations are evaluated when the generated module is imported, a crafted value can execute arbitrary Python code. Version 0.70.6 fixes the vulnerability by restricting the value to a bare name or a call to a bare name with literal arguments.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
dataclasses-avroschemato a version that resolves this vulnerability.Fixed in 0.70.6
Event History
Frequently Asked Questions
Which deployments are affected?
Deployments using dataclasses-avroschema versions 0.44.0 through 0.70.5 are affected when they generate Pydantic or AvroDantic models from an Avro schema containing a crafted pydantic-class field value.
What must an attacker control for exploitation?
An attacker needs to supply or influence an Avro schema whose field metadata includes a malicious pydantic-class value, and that schema must be used to generate Python code. The generated module must then be imported, because the field annotations are evaluated at import time.
What should be done if patching is not immediately possible?
Do not generate or import models from untrusted Avro schemas, and review schema inputs for pydantic-class metadata values. Restrict generation to schemas from trusted sources until an upgrade is possible.
How can I determine whether generated code may be affected?
Inspect generated Pydantic or AvroDantic model code for field annotations constructed from schema pydantic-class values after the pydantic. prefix. Generated modules from schemas with untrusted or unexpected values should be treated as potentially unsafe to import.
What version contains the fix?
Version 0.70.6 restricts pydantic-class values to a bare name or a call to a bare name with literal arguments.