Summary
LiteLLM's MCP preview endpoints accepted attacker-controlled command, args, and env fields in server configurations and executed them as subprocesses on the proxy host.
Any user with a valid LiteLLM proxy API key, including low-privilege internal keys, could trigger arbitrary command execution with the privileges of the proxy process.
Affected context
This vulnerability affects LiteLLM deployments using versions 1.74.2 through 1.83.6 where:
- MCP functionality is enabled or exposed, and
- The REST preview endpoints for testing MCP servers are reachable by users (e.g., internal users, service accounts, or other systems) holding valid proxy API keys.
The issue resides in POST endpoints /mcp-rest/test/connection and /mcp-rest/test/tools/list, which accept and act on full stdio-based MCP server configurations. Environments with broad API key distribution or weak separation between administrative and non-administrative keys are at higher risk.
Exploit preconditions
- Attack surface: HTTP(S) interface of the LiteLLM proxy, specifically:
POST /mcp-rest/test/connectionPOST /mcp-rest/test/tools/list- Required access:
- Possession of any valid LiteLLM proxy API key that can call these endpoints.
- No elevated or administrative role is needed; low-privilege internal keys suffice if not restricted at another layer.
- Trigger point:
- Sending a crafted MCP configuration in the request body using stdio transport, where the
command,args, and/orenvfields are set to attacker-chosen values. - The server attempts to "preview" the MCP, spawning the provided command as a subprocess.
- Why exploitation is possible:
- The preview endpoints directly pass user-controlled configuration values to the subprocess-launching logic.
- There is no privilege or role check separating "test/preview" functionality from regular low-privilege API usage.
- In affected versions, configuration used for transient preview is trusted as executable command configuration without sufficient restriction or validation.
Why this happens
The core issue is treating untrusted configuration data as executable process configuration for stdio-based MCP servers.
In affected LiteLLM versions, the MCP preview endpoints accept arbitrary command, args, and env fields from the request body and use them to spawn a subprocess on the proxy host.
This behavior embodies CWE-78: Improper Neutralization of Special Elements used in an OS Command, and is closely related to CWE-77: Command Injection, because:
- Input that should be considered untrusted is used to construct or invoke operating system commands.
- The application path for "test connection" does not distinguish between safe configuration parameters and parameters that directly control executable behavior.
Conceptually, the bug class is "command execution by design" without enforcing any trust boundary: a feature meant for privileged operators (testing new MCP configurations) is exposed to all API-key holders, effectively giving them process-spawning capability on the server.
Potential impact
- Remote execution of arbitrary commands on the LiteLLM proxy host with the privileges of the proxy process.
- Full compromise of the LiteLLM gateway environment, including access to in-memory secrets, configuration files, and cached data.
- Lateral movement into adjacent systems reachable from the proxy host (e.g., internal networks, databases, or other services).
- Tampering with logs, local configuration, or the host runtime to conceal activity or establish persistence.
- Abuse of the host to launch further attacks, such as data exfiltration or internal scanning.
General mitigation guidance
Defenses should focus on tightening execution boundaries, reducing implicit trust in configuration, and isolating any process-spawning functionality:
- Constrain command execution surfaces:
- Avoid exposing endpoints that directly accept executable commands or arguments from regular users.
- Restrict "test/preview" capabilities to carefully controlled internal workflows or remove them from general-purpose APIs.
- Enforce strong authorization models:
- Treat any action that can spawn processes or touch the OS as a privileged operation requiring explicit administrative roles or separate credentials.
- Apply fine-grained access control so low-privilege API keys cannot reach process-launching APIs.
- Harden configuration handling:
- Treat MCP server configurations as untrusted unless they originate from known administrative channels.
- Validate configurations against a strict schema that constrains allowed commands, paths, and environment variables, or map configurations to a fixed allowlist of known-safe executables.
- Apply least privilege and isolation:
- Run the LiteLLM proxy under a dedicated low-privilege service account.
- Use OS-level sandboxing or containerization to isolate any subprocesses that must be spawned, reducing their ability to impact the host.
- Limit filesystem and network permissions so that even if commands run, their reach is minimized.
- Secure API key distribution and policies:
- Separate keys used for administrative operations from keys used by regular users or services.
- Rotate and scope API keys, assigning only the minimal permissions needed for their use cases.
How teams detect issues like this
Detection should combine runtime monitoring, code-level review, and policy enforcement:
- Static analysis and code review:
- Search for code paths where HTTP request parameters or configuration fields influence process-spawning APIs (e.g.,
subprocess, equivalent process execution mechanisms, or wrappers). - Flag handlers that allow arbitrary
command,args, or similar fields to flow into execution contexts without validation or authorization checks. - Review "test/preview" endpoints to ensure they are not available to low-privilege roles and do not bypass normal policy enforcement.
- Runtime monitoring and logging:
- Enable detailed logging for:
- Calls to MCP preview or configuration endpoints.
- Subprocess creation originating from the LiteLLM proxy.
- Monitor for unusual process trees, unexpected commands, or anomalous arguments originating from the proxy service account.
- Use host intrusion detection systems (HIDS) or EDR solutions to flag suspicious command patterns or filesystem/network activity from the proxy.
- Policy and CI/CD enforcement:
- Integrate security checks into CI to catch new endpoints or changes that feed user-controlled data into command execution mechanisms.
- Apply API gateway or service mesh policies to limit who can access administrative or testing endpoints.
- Periodically audit API key usage and identify keys that invoke process-spawning or configuration-testing endpoints.

