Summary
A code injection flaw in uproot's ROOT file parsing allows attacker-controlled metadata fields to be interpolated directly into dynamically generated Python source code.
When a crafted ROOT file is opened and processed through affected uproot code paths, the injected Python expressions can be executed in the context of the application, leading to arbitrary code execution.
Affected context
This vulnerability occurs in applications that use uproot to open and process ROOT files, particularly where TStreamerInfo records are parsed and corresponding Python reader classes are generated at runtime.
It becomes relevant when streamer metadata fields from the file, such as element names, are inserted into the generated Python source without safe quoting or escaping.
The risk is most pronounced in environments that consume untrusted or externally supplied ROOT files, such as data ingestion pipelines, shared analysis platforms, or automated batch-processing systems.
Exploit preconditions
- Attack surface: ROOT file parsing via uproot, specifically code paths that dynamically generate and compile Python classes from TStreamerInfo.
- Required access: Ability to supply or influence ROOT files processed by the application (e.g., upload, file drop, or control over input datasets).
- Trigger point: Opening and reading a crafted ROOT file that contains malicious streamer metadata; uproot generates and invokes a reader method using interpolated, unsafely quoted metadata.
- Why exploitation is possible: Certain streamer metadata fields are interpolated into Python source code without protective quoting (e.g., via
repr()or!r), enabling attacker-supplied content to break out of expected expressions and introduce arbitrary Python code that is compiled and executed.
Why this happens
The underlying bug stems from unsafe construction of executable Python source code using data fields drawn directly from a file format without appropriate sanitization or quoting.
In affected uproot code paths, metadata from ROOT TStreamerInfo records, such as element names, are interpolated into dynamically generated Python class definitions as if they were trusted identifiers or literals.
Without using mechanisms like repr() or the !r format specifier to safely quote these values, an attacker can embed expression-breaking characters and Python syntax into the metadata fields.
This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), where external input is allowed to shape executable code in a way that permits unintended execution of attacker-provided logic.
Potential impact
- Arbitrary Python code execution within the application process that opens the malicious ROOT file
- Compromise of the local runtime environment, including access to in-memory data and application secrets
- Unauthorized file access, modification, or deletion on the host system, subject to process privileges
- Use of the compromised application as a pivot for wider system or network attacks
- Manipulation or corruption of scientific or analytical data processed from ROOT files
General mitigation guidance
Effective mitigation focuses on separating untrusted file metadata from executable code and constraining how dynamic code is generated:
- Ensure all file-controlled metadata fields used in dynamic source generation are safely quoted or escaped, for example via
repr()or equivalent mechanisms that treat them as data rather than code. - Prefer structured code generation patterns that do not directly embed raw strings from the input into executable expressions, using parameterization or template systems with strict escaping rules.
- Reduce reliance on dynamic compilation where possible in favor of static, schema-driven parsing logic that treats metadata as data-only.
- Run file-parsing components with least privilege and isolated execution contexts (e.g., sandboxed workers or restricted environments) so that, if a parsing defect is present, the impact is constrained.
- Apply stricter input validation and sanity checks on streamer metadata fields before they are used in any code-generation routines, rejecting or safely handling unexpected or malformed values.
How teams detect issues like this
Organizations can detect similar vulnerabilities through a mix of static analysis, targeted code review, and policy enforcement:
- Use static analysis rules or linters to flag patterns where dynamic source code is constructed using f-strings,
format(), or string concatenation with untrusted inputs. - During code review, pay attention to any logic that generates or compiles code at runtime (e.g.,
exec,eval,compile) and verify that all interpolated values are properly quoted, escaped, or otherwise constrained. - Define internal security guidelines that discourage unrestricted dynamic code generation, requiring justification and defensive patterns (such as strict input normalization and sandboxing) when it is unavoidable.
- Employ automated security scanning tools that understand common code injection patterns and can alert on use of dangerous APIs combined with external data sources like file formats.

