Summary
dataclasses-avroschema embeds schema-controlled default values into generated Python source without escaping them. A crafted default may break out of a string literal and inject statements that execute when the generated module is imported.
dataclasses-avroschema embeds schema-controlled default values into generated Python source without escaping them. A crafted default may break out of a string literal and inject statements that execute when the generated module is imported.
Affected context
The vulnerability affects workflows that generate Python code from Avro schemas and render string, UUID, bytes, or fixed-field defaults into Python string literals. Risk exists when an attacker can influence the schema or its default values and the resulting module is later imported or executed.
The vulnerability affects workflows that generate Python code from Avro schemas and render string, UUID, bytes, or fixed-field defaults into Python string literals. Risk exists when an attacker can influence the schema or its default values and the resulting module is later imported or executed.
Exploit preconditions
- Attack surface: Avro-to-Python source generation
- Required access: Ability to provide or modify an Avro schema or a field default
- Trigger point: Import or execution of the generated Python module
- Why exploitation is possible: Schema-controlled values are inserted into
Python source without sufficient escaping, allowing generated syntax to
contain unintended statements
- Attack surface: Avro-to-Python source generation
- Required access: Ability to provide or modify an Avro schema or a field default
- Trigger point: Import or execution of the generated Python module
- Why exploitation is possible: Schema-controlled values are inserted into
Python source without sufficient escaping, allowing generated syntax to
contain unintended statements
Why this happens
The underlying flaw is improper neutralization of schema data when it is rendered into generated Python source. Field defaults are placed inside quoted literals without escaping characters that can terminate those literals or alter the surrounding syntax. This maps to CWE-94, because untrusted or insufficiently constrained data becomes executable code during source generation and subsequent module import.
The underlying flaw is improper neutralization of schema data when it is rendered into generated Python source. Field defaults are placed inside quoted literals without escaping characters that can terminate those literals or alter the surrounding syntax. This maps to CWE-94, because untrusted or insufficiently constrained data becomes executable code during source generation and subsequent module import.
Potential impact
- An attacker may execute arbitrary Python statements in the importing process
- The application environment could be compromised
- Credentials, configuration, or data accessible to the process could be exposed
- Generated artifacts could be altered to support persistence or supply-chain abuse
- An attacker may execute arbitrary Python statements in the importing process
- The application environment could be compromised
- Credentials, configuration, or data accessible to the process could be exposed
- Generated artifacts could be altered to support persistence or supply-chain abuse
General mitigation guidance
Mitigation generally focuses on treating schema content as untrusted data
throughout code-generation workflows.
Common defensive patterns include:
- Escaping generated string literals with language-aware serialization routines
- Prefering structured runtime data or safe serializers over handwritten source interpolation
- Validating schema defaults against strict type and format constraints before generation
- Separating generated artifacts from trusted application code and reviewing them before import
- Restricting the privileges, filesystem access, and secrets available to processes that import generated modules
- Preventing untrusted parties from modifying schemas or publishing generated artifacts
Mitigation generally focuses on treating schema content as untrusted data
throughout code-generation workflows.
Common defensive patterns include:
- Escaping generated string literals with language-aware serialization routines
- Prefering structured runtime data or safe serializers over handwritten source interpolation
- Validating schema defaults against strict type and format constraints before generation
- Separating generated artifacts from trusted application code and reviewing them before import
- Restricting the privileges, filesystem access, and secrets available to processes that import generated modules
- Preventing untrusted parties from modifying schemas or publishing generated artifacts
How teams detect issues like this
Detection approaches may include:
- Static analysis rules for string interpolation or concatenation into generated source
- Code review checks for schema values inserted into quoted Python literals
- Tests using boundary characters and representative defaults to verify correct escaping
- Artifact scanning and policy enforcement before generated modules are imported or distributed
- Monitoring unexpected imports, process execution, or changes to generated code
Automated code review and software composition analysis tools may help identify
unsafe code-generation patterns and affected dependency usage.
Detection approaches may include:
- Static analysis rules for string interpolation or concatenation into generated source
- Code review checks for schema values inserted into quoted Python literals
- Tests using boundary characters and representative defaults to verify correct escaping
- Artifact scanning and policy enforcement before generated modules are imported or distributed
- Monitoring unexpected imports, process execution, or changes to generated code
Automated code review and software composition analysis tools may help identify
unsafe code-generation patterns and affected dependency usage.

