/

CVE-2026-42203

Severity:

HIGH RISK

(8.8)

Template Injection (CWE-1336) in LiteLLM Prompt Tester

CVE-2026-42203

Modified

Vulnerability type

Category:

Template Injection / Code Injection

CWE:

CWE-1336, CWE-94

Impact:

Remote Code Execution within LiteLLM Proxy

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 /prompts/test endpoint accepted user-supplied templates and evaluated them without sandboxing, enabling execution of arbitrary code in the proxy process.

Any caller with a valid proxy API key could exploit this behavior, potentially accessing secrets or issuing commands on the host system where LiteLLM runs.

Affected context

The vulnerability arises in deployments of the LiteLLM proxy that expose the POST /prompts/test endpoint to authenticated users.

In affected versions, prompt templates supplied through this endpoint were rendered using an execution-capable templating mechanism without isolation.

Risk is elevated when the proxy process holds sensitive environment variables, filesystem access, or network connectivity to upstream services and databases.

Exploit preconditions

  • Attack surface: HTTP POST requests to the /prompts/test endpoint on the LiteLLM proxy.
  • Required access: Ability to authenticate using a valid LiteLLM proxy API key; no additional privileges are required.
  • Trigger point: Submission of a crafted prompt template that is rendered by the test endpoint's unsandboxed template engine.
  • Why exploitation is possible: The rendering mechanism executes template expressions directly within the proxy process context, with no sandboxing or restriction on accessible modules, functions, or environment data.

Why this happens

This issue stems from treating user-controlled prompt templates as trusted code-like input and feeding them to an execution-capable template engine running inside the LiteLLM proxy process.

The design did not separate template evaluation from the application's runtime privileges, nor did it constrain what operations templates could perform.

Conceptually, this maps to CWE-1336: Improperly Controlled Template Injection, and overlaps with CWE-94: Improper Control of Code Generation, where dynamically evaluated templates act as a vehicle for arbitrary code execution.

Potential impact

  • An attacker may execute arbitrary Python code within the LiteLLM proxy process.
  • Attackers could access or exfiltrate sensitive environment variables such as provider API keys or database credentials.
  • Attackers may read or modify files accessible to the proxy on the host filesystem.
  • The proxy could be used as a pivot to issue unauthorized requests to upstream LLM providers or internal services.
  • Depending on deployment permissions, arbitrary command execution on the host operating system may be possible.

General mitigation guidance

Effective mitigation focuses on removing code-execution capabilities from user-supplied templates and isolating any remaining dynamic rendering.

Common defensive patterns include:

  • Using purely declarative template languages that do not support arbitrary code execution or access to application internals.
  • Strictly whitelisting allowed template functions and variables, and rejecting constructs outside that safe surface.
  • Rendering templates in a sandboxed environment with constrained permissions, separate from the primary proxy process.
  • Treating authenticated users as potentially untrusted and enforcing least-privilege on runtime credentials and filesystem access.
  • Avoiding storage of long-lived secrets in the main proxy process where possible, or limiting their exposure via environment and configuration.

How teams detect issues like this

High-level detection approaches include:

  • Static analysis rules flagging use of execution-capable template engines with user-controlled input and no sandbox or whitelist.
  • Code review checklists that require explicit documentation of template evaluation boundaries, accessible context, and security controls.
  • Runtime monitoring and logging of template evaluation paths, including anomalous template structures or exceptions triggered during rendering.
  • Security policy enforcement that disallows dynamic code generation based on request data, especially in administrative or testing endpoints.
  • Automated application security testing tools configured to probe template endpoints with payloads indicative of template injection behavior.

Sources

SourceLink
github.comgithub.com/BerriAI/litellm/releases/tag/v1.83.7-stable
github.comgithub.com/BerriAI/litellm/security/advisories/GHSA-xqmj-j6mv-4862
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-42203
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2467917
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-42203.json

Frequently asked

questions

It is exploitable over the network wherever the LiteLLM proxy's /prompts/test endpoint is exposed, as long as the attacker can supply crafted templates and authenticate using a valid proxy API key.

The attacker only needs access to a valid LiteLLM proxy API key; they do not require host-level accounts or direct shell access. Once authenticated, they can send malicious templates to the affected endpoint.

The safest pattern is to avoid any template evaluation that can execute code derived from user input. Use strictly declarative templates, apply strong whitelisting for allowed constructs, or perform rendering in a sandbox with tightly constrained capabilities.

During design and implementation, treat all user-controllable templates and configuration data as untrusted, perform threat modeling on template engines, enforce least-privilege for processes handling dynamic input, and integrate static analysis and code review checks specifically targeting dynamic evaluation and template rendering paths.

Find out what's already
exploitable in your codebase.