AgentbeamBeta
AI agent vulnerability · LiteLLM

CVE-2024-2952: LiteLLM has Server-Side Template Injection vulnerability in /completions endpoint

criticalCVSS 3.0 9.8GHSA-46cm-pfwv-cgf8

LiteLLM before 1.34.42 has a server-side template injection in the /completions endpoint. The hf_chat_template method renders the chat_template value from a model's tokenizer_config.json through Jinja without sandboxing, so a crafted file executes code on the server. Upgrade to litellm 1.34.42.

Published Apr 10, 2024 · Updated Jul 6, 2026 · Analysis Nov 18, 2026

What an attacker can do

For Hugging Face models, LiteLLM's proxy fetches tokenizer_config.json and passes its chat_template string to hf_chat_template, which renders it with the Jinja template engine. A normal Jinja environment lets a template reach Python objects, so a malicious template can run arbitrary code. An attacker who controls the tokenizer_config.json that the proxy loads, for instance by pointing a request at an attacker-controlled model repository, gets code execution in the proxy process.

The CVSS 3.0 vector (AV:N/AC:L/PR:N/UI:N) rates it 9.8 with no authentication. LiteLLM proxies hold provider API keys, the database connection and the master key, so code execution exposes all of them and lets the attacker use the upstream accounts. How easy it is to reach depends on whether callers can name arbitrary Hugging Face model sources through the proxy.

Who is affected

The pip package litellm is affected before 1.34.42, in proxy deployments whose /completions endpoint can be used with Hugging Face models by untrusted callers.

Check the version:

pip show litellm

For Docker, check the image tag.

litellm

Ecosystem
PyPI
Affected
< 1.34.42
Fixed in
1.34.42
Check
pip show litellm

How to fix it

Upgrade to litellm 1.34.42:

pip install --upgrade litellm==1.34.42

Pull request 2941 switches Jinja rendering to the ImmutableSandboxedEnvironment, which stops templates reaching dangerous Python objects. The sources we read give no workaround. Until you upgrade, restrict which models and model sources callers can name, and rotate provider keys if you suspect abuse.

How to tell if you were hit

Look at proxy logs for requests to /completions that name unfamiliar Hugging Face repositories, and for fetches of tokenizer_config.json from unexpected sources. Check for unexpected child processes of the proxy, outbound connections to unknown hosts, and use of your provider keys that you cannot match to normal traffic.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

BerriAI/litellm is vulnerable to Server-Side Template Injection (SSTI) via the /completions endpoint. The vulnerability arises from the hf_chat_template method processing the chat_template parameter from the tokenizer_config.json file through the Jinja template engine without proper sanitization. Attackers can exploit this by crafting malicious tokenizer_config.json files that execute arbitrary code on the server.

Credited to ishaan-jaff, r3kumar, cookesan.

Questions

Which LiteLLM version fixes CVE-2024-2952?

LiteLLM 1.34.42 fixes it. Every version before 1.34.42 is affected, so upgrade the package.

What triggers the bug?

A tokenizer_config.json whose chat_template holds a malicious Jinja expression. The proxy renders it without a sandbox through hf_chat_template.

What did the fix change?

Pull request 2941 moves rendering to Jinja2's ImmutableSandboxedEnvironment, according to the commit titles on the PR.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More LiteLLM vulnerabilities

All LiteLLM entries