Summary
Hydra's hydra.utils.instantiate() can resolve and call Python objects selected through configuration, including attacker-controlled targets and arguments. When an application passes untrusted configuration, CLI overrides, or model metadata to this function, an attacker may execute arbitrary code within the application's process.
Affected context
The vulnerability occurs in applications, libraries, command-line workflows, or model-loading pipelines that use Hydra's instantiation functionality with configuration data that is not fully trusted. Risk is higher when users, external files, model metadata, automation systems, or other inputs can influence target names or arguments before they are validated and restricted.
Exploit preconditions
- Attack surface: Hydra configuration processing and calls to
hydra.utils.instantiate() - Required access: Ability to influence configuration, CLI overrides, model metadata, or another input consumed by the instantiation path
- Trigger point: Resolution and invocation of a configured target object
- Why exploitation is possible: Target values and arguments can select callable Python objects without sufficiently restricting which objects may be resolved and executed
Why this happens
The underlying flaw is unsafe dynamic resolution of Python objects from attacker-influenced configuration. Hydra resolves a configured target and invokes it as part of object instantiation, allowing untrusted values to control executable behavior rather than merely representing data. This maps primarily to CWE-94: Improper Control of Generation of Code, with CWE-470: Use of Externally-Controlled Input to Select Classes or Code also describing the unsafe selection pattern.
Potential impact
- An attacker may execute arbitrary code in the affected process
- The process could read or modify accessible files and credentials
- Application data, model artifacts, or configuration could be altered
- The service or workflow could be terminated or disrupted
- Compromise could extend to other resources available to the process
General mitigation guidance
Mitigation generally focuses on reducing trust in configuration-driven object resolution and ensuring that only explicitly approved targets can be instantiated.
Common defensive patterns include:
- Restricting instantiation to a narrowly defined allowlist of safe target types
- Rejecting arbitrary target paths and dynamically selected callables
- Separating data-only configuration from executable object construction
- Validating configuration and metadata against strict schemas before resolution
- Treating CLI overrides, model metadata, and external files as untrusted input
- Running affected workflows with least-privilege identities and limited filesystem and credential access
- Applying security-focused process isolation where dynamic instantiation is unavoidable
- Using a maintained Hydra release that provides target-blocking controls, while avoiding broad allowlist overrides
How teams detect issues like this
High-level detection can include:
- Static analysis searches for
hydra.utils.instantiate()calls receiving external, deserialized, or user-controlled configuration - Code review checks for unrestricted target fields, broad allowlists, and configuration values passed directly into object resolution
- Dependency and policy scans that identify Hydra versions lacking target-blocking behavior
- Runtime monitoring for unexpected child processes, file access, credential reads, or process termination during configuration loading
- CI policies requiring explicit approval for dynamic imports, reflection, or configuration-controlled callable execution
- Automated code review tools configured to flag externally controlled class or function selection

