/

CVE-2026-42271

Severity:

HIGH RISK

(8.8)

Command Injection in LiteLLM AI Gateway

CVE-2026-42271

Analyzed

Vulnerability type

Category:

Command Injection

CWE:

CWE-77, CWE-78

Impact:

Remote Code Execution on LiteLLM Proxy Host

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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/connection
  • POST /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/or env fields 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.

Sources

SourceLink
github.comgithub.com/BerriAI/litellm/releases/tag/v1.83.7-stable
github.comgithub.com/BerriAI/litellm/security/advisories/GHSA-v4p8-mg3p-g94g
access.redhat.comaccess.redhat.com/errata/RHSA-2026:27784
access.redhat.comaccess.redhat.com/errata/RHSA-2026:28960
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30056
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-42271
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2467924
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-42271.json
cisa.govcisa.gov/known-exploited-vulnerabilities-catalog?field_cve=CVE-2026-42271

Frequently asked

questions

Any environment where the affected LiteLLM version is deployed and where users or services hold valid proxy API keys that can reach the MCP preview endpoints is potentially affected. The attack does not require network-level compromise, only the ability to call these endpoints with a valid key.

The attacker needs a valid LiteLLM proxy API key that can invoke /mcp-rest/test/connection or /mcp-rest/test/tools/list. No administrative or elevated privileges are inherently required if the deployment does not enforce additional role-based restrictions.

Treat any capability that can spawn OS processes as a privileged operation, and ensure it is never directly driven by untrusted input. Centralize command execution behind strictly controlled interfaces, require explicit administrative authorization, and restrict inputs to a constrained, validated set of allowable commands.

Apply a "no user-controlled commands" design rule: external inputs, including configurations, should not dictate executable commands or process arguments. Combine that with strong role-based access control for operational features, strict schema validation for configuration, least-privilege process isolation, and security review of any endpoint that can influence the host operating system.

Find out what's already
exploitable in your codebase.