Summary
dataclasses-avroschema can embed a fixed type's aliases value directly into generated Python annotations without ensuring that the value is a list. If an attacker can supply or influence a crafted Avro schema and the generated module is later imported, the injected expression may execute with the module's privileges.
dataclasses-avroschema can embed a fixed type's aliases value directly into generated Python annotations without ensuring that the value is a list. If an attacker can supply or influence a crafted Avro schema and the generated module is later imported, the injected expression may execute with the module's privileges.
Affected context
The vulnerability occurs in schema-to-code generation workflows that process fixed Avro types and emit Python source code. It becomes risky when an attacker can influence the Avro schema, the generated source is written to a location that will be imported, and the import occurs in a sufficiently privileged environment.
The vulnerability occurs in schema-to-code generation workflows that process fixed Avro types and emit Python source code. It becomes risky when an attacker can influence the Avro schema, the generated source is written to a location that will be imported, and the import occurs in a sufficiently privileged environment.
Exploit preconditions
- Attack surface: Avro schema processing and Python code generation
- Required access: Ability to provide or modify a schema containing a crafted fixed type
- Trigger point: Generation followed by import or execution of the resulting Python module
- Why exploitation is possible: A non-list aliases value can be interpolated as an unquoted Python expression in generated source code
- Attack surface: Avro schema processing and Python code generation
- Required access: Ability to provide or modify a schema containing a crafted fixed type
- Trigger point: Generation followed by import or execution of the resulting Python module
- Why exploitation is possible: A non-list aliases value can be interpolated as an unquoted Python expression in generated source code
Why this happens
The underlying bug is insufficient validation and escaping of schema metadata before it is inserted into generated Python code. Although aliases is expected to be represented as a list, a bare string can pass through generation and become executable syntax rather than inert data. This maps to CWE-94: Improper Control of Generation of Code, because attacker-influenced input affects the contents of generated code.
The underlying bug is insufficient validation and escaping of schema metadata before it is inserted into generated Python code. Although aliases is expected to be represented as a list, a bare string can pass through generation and become executable syntax rather than inert data. This maps to CWE-94: Improper Control of Generation of Code, because attacker-influenced input affects the contents of generated code.
Potential impact
- Arbitrary Python code execution in the process importing the generated module
- Access to application data, credentials, and environment variables
- Modification or deletion of files available to the process
- Further compromise of connected services or build environments
- Supply-chain or build-pipeline tampering
- Arbitrary Python code execution in the process importing the generated module
- Access to application data, credentials, and environment variables
- Modification or deletion of files available to the process
- Further compromise of connected services or build environments
- Supply-chain or build-pipeline tampering
General mitigation guidance
Mitigation generally focuses on treating schemas as untrusted input and preventing metadata from becoming executable source code.
Common defensive patterns include:
- Enforcing that aliases is a list before code generation
- Rejecting unexpected types, expressions, and syntax-bearing values
- Escaping or safely serializing values inserted into generated Python
- Preferentially generating data through structured APIs rather than source-code interpolation
- Separating generation from import or execution and applying least privilege to generation jobs
- Restricting schema provenance, write access, and execution of generated artifacts
These controls reduce exposure even when a schema is obtained from an external or semi-trusted source.
Mitigation generally focuses on treating schemas as untrusted input and preventing metadata from becoming executable source code.
Common defensive patterns include:
- Enforcing that aliases is a list before code generation
- Rejecting unexpected types, expressions, and syntax-bearing values
- Escaping or safely serializing values inserted into generated Python
- Preferentially generating data through structured APIs rather than source-code interpolation
- Separating generation from import or execution and applying least privilege to generation jobs
- Restricting schema provenance, write access, and execution of generated artifacts
These controls reduce exposure even when a schema is obtained from an external or semi-trusted source.
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules identifying string interpolation into generated source code
- Code review checks for schema values inserted without type validation or escaping
- Tests using unexpected scalar, expression-like, and malformed metadata values
- Dependency and component policies that flag unsafe code-generation paths
- Runtime monitoring for unexpected imports, subprocess creation, or file access during schema generation
Automated security review tools may help identify generated-code sinks, but findings should be validated against the complete generation and import workflow.
Organizations can look for this class of issue through:
- Static analysis rules identifying string interpolation into generated source code
- Code review checks for schema values inserted without type validation or escaping
- Tests using unexpected scalar, expression-like, and malformed metadata values
- Dependency and component policies that flag unsafe code-generation paths
- Runtime monitoring for unexpected imports, subprocess creation, or file access during schema generation
Automated security review tools may help identify generated-code sinks, but findings should be validated against the complete generation and import workflow.

