Summary
A command injection vulnerability in MLflow's model serving initialization allows attacker-controlled dependency specifications from python_env.yaml to be interpolated directly into a shell command.
When a malicious model artifact is deployed with env_manager=LOCAL, this flaw can enable arbitrary command execution on the host running the MLflow model serving container.
Affected context
This vulnerability arises in MLflow deployments that:
- Use MLflow model serving with
env_manager=LOCAL, and - Automatically install model dependencies from a
python_env.yamlfile inside the model artifact, and - Construct shell commands from these dependencies without robust quoting or sanitization.
It primarily affects environments where untrusted or externally supplied model artifacts can be registered, stored, or deployed, such as shared model registries or CI/CD-driven model promotion pipelines.
Exploit preconditions
- Attack surface: MLflow model serving API or any deployment pipeline that pulls and serves MLflow model artifacts.
- Required access: Ability to upload, register, replace, or otherwise influence the model artifact containing
python_env.yaml. - Trigger point: Deployment or initialization of a model with
env_manager=LOCAL, where_install_model_dependencies_to_env()processes thepython_env.yamland constructs a shell command. - Why exploitation is possible: Dependency entries from
python_env.yamlare interpolated directly into a shell command without strict quoting, escaping, or validation, allowing shell metacharacters to introduce additional commands.
Why this happens
The root cause maps to CWE-77: Command Injection. The _install_model_dependencies_to_env() function implicitly trusts data from python_env.yaml, which is part of the model artifact and can be crafted by an attacker.
Instead of treating dependency specifications as data passed to a parameterized process invocation, the implementation builds a shell command string and interpolates these values directly. In shells, characters like ;, &&, |, backticks, and $() are interpreted as control operators or subshells. When unvalidated user-controlled values reach such command contexts, the shell parser merges them into the executable logic, enabling arbitrary commands to run under the privileges of the MLflow serving process.
Potential impact
- Arbitrary OS command execution on the host or container running MLflow model serving.
- Unauthorized access to environment variables, credentials, and secrets available to the MLflow process.
- Exfiltration or tampering with training data, model artifacts, or inference traffic.
- Lateral movement within the surrounding infrastructure or Kubernetes cluster.
- Deployment of persistence mechanisms or additional malware on the serving host.
- Compromise of CI/CD or MLOps pipelines that automatically deploy newly registered models.
General mitigation guidance
Effective mitigation focuses on eliminating shell-based interpolation of untrusted data and tightening trust boundaries around model artifacts:
- Prefer API-level or library-level process invocation (e.g.,
subprocesswith argument lists, package manager APIs) instead of constructing raw shell command strings. - Treat
python_env.yamland similar artifact configuration files as untrusted input, even when sourced from internal registries; enforce strict schema validation and reject unexpected fields or characters. - Apply robust quoting and escaping only as a secondary safeguard; the primary defense should be avoiding the shell where possible.
- Introduce an allowlist-based policy for dependency sources and formats (e.g., only standard PyPI specifiers, no inline scripts, no arbitrary URLs or VCS references unless explicitly required and constrained).
- Run model serving infrastructure with least privileges, restricting filesystem access, network egress, and access to sensitive credentials to limit blast radius if a similar issue occurs.
- Segment environments so that models from low-trust sources are deployed into isolated runtimes with tighter controls and reduced access to production data and systems.
How teams detect issues like this
Detection typically combines code-level and operational monitoring approaches:
- Static analysis and code review:
- Flag any usage of shell-based process execution (
sh -c,bash -c, orsubprocesswithshell=True) that includes data derived from model artifacts, configuration files, or user input. - Highlight string concatenation or f-strings used to build command lines from
python_env.yamlfields or other external data. - Enforce secure coding guidelines through linters or SAST tools that specifically look for command injection patterns and shell metacharacters in constructed commands.
- Configuration and policy enforcement:
- Require security review for any code path that executes package managers or system tools based on runtime configuration.
- Implement CI policies that block new uses of shell invocation APIs where arguments are not passed as separate parameters.
- Runtime monitoring:
- Monitor model serving hosts or containers for anomalous process trees spawned from the MLflow service.
- Use logging and SIEM integration to detect unusual command executions, unexpected network activity, or access to sensitive files during model deployment.

