What happened
LiteLLM is an open-source tool that companies use to connect their applications to large language models from providers such as OpenAI, Anthropic or Google. It often runs as a standalone server, an AI gateway (proxy) that manages API keys, budgets and usage rules for the whole organization.
On April 10, 2026, vulnerability CVE-2026-40217 was published. It affects a feature for testing custom protection rules (guardrails), available at /guardrails/test_custom_code. An attacker with even basic access to LiteLLM can use it to run arbitrary code of their choosing on the server. According to the NVD record, LiteLLM versions released up to and including April 8, 2026 are affected.
The flaw is referenced in a security advisory from X41 D-Sec. Red Hat, which ships LiteLLM in several of its products, also responded and released fixes for them in June 2026.
The European Union Vulnerability Database (EUVD), run by ENISA, has listed the flaw as actively exploited since November 18, 2026. If you run LiteLLM and have not updated it yet, now is the time.
Why it is dangerous
This is a code injection flaw (CWE-94) combined with an unprotected alternate channel (CWE-420). Picture a building where a guard checks what everyone carries at the main entrance, but nobody checks anything at the staff-only service door. The custom code testing feature is that service door: it was meant for trying out rules, but an attacker can use it to run anything.
The attack works over the network and needs no action from a victim. The attacker does need a low-privilege login, typically a valid LiteLLM key or account. That is not much of a barrier, since gateway keys tend to be handed out to many people and applications, and they sometimes leak in code or configuration files.
If the attack succeeds, the attacker runs code with the privileges of the LiteLLM process. That can expose API keys for paid AI services and the data flowing through the gateway, and open a path to other systems on the network the server can reach. Red Hat notes that actions performed by injected code of this kind often go unlogged.
- CVSS 8.8 out of 10 (high severity): the score was assigned by MITRE, which runs the CVE program, and Red Hat gives the same value. CVSS is an international scale that rates how serious a flaw’s impact is and how easy it is to exploit.
- Red Hat rates the flaw “Important” overall and marked its Ansible Automation Platform update as “Critical”.
- EPSS about 17%: the EPSS model estimates the probability that a flaw will be exploited in the next 30 days. As of November 18, 2026, this score is higher than for 97% of all known vulnerabilities.
- EUVD: ENISA’s European database has listed the flaw as exploited since November 18, 2026.
Who is affected
Anyone running a LiteLLM version released up to and including April 8, 2026 is at risk, especially when it runs as a server (AI gateway). Typical setups are company servers or Docker and Kubernetes containers through which internal apps, chatbots or developers reach AI models. The risk is highest where the gateway is reachable from the internet or used by many people.
LiteLLM often ends up in a company indirectly, bundled inside other AI tools. Red Hat has fixed the flaw in these products:
- Red Hat Ansible Automation Platform 2.6 (container release)
- Red Hat OpenShift AI 3.3 (fixed in 3.3.4)
Red Hat also assessed Lightspeed Core, so check its current status on the CVE-2026-40217 page of the Red Hat Customer Portal. If you only use LiteLLM as a library in scripts and never start its server, the vulnerable web feature is most likely not reachable in your setup. Do not put off the update anyway.
How to check if you are affected
This command shows the installed package version. It changes nothing, it only prints information:
pip show litellm
If LiteLLM runs in Docker, find the container first and then check the version inside it:
docker ps --format '{{.Names}} {{.Image}}' | grep -i litellm
docker exec CONTAINER_NAME pip show litellm
A LiteLLM version number does not tell you its release date. Look the date up on the project’s PyPI page (pypi.org/project/litellm) or in its GitHub releases. If your version came out on or before April 8, 2026, you are affected.
For Red Hat OpenShift AI, the command below shows the operator version. For Ansible Automation Platform, check the “About” dialog in the web console.
oc get csv -A | grep -i rhods
How to fix it
Neither NVD nor Red Hat names a specific fixed LiteLLM version. Red Hat also states that no mitigation is available that meets its criteria. Updating is therefore the only reliable fix. Work through it in this order:
- Start with servers reachable from the internet or shared by many users. Until they are updated, restrict access to the internal network or VPN only.
- Update LiteLLM to the latest version and confirm in the release notes that it was released after April 8, 2026 and addresses CVE-2026-40217.
- For containers, pull a newer image and recreate the container. A restart alone is not enough.
- Ansible Automation Platform 2.6: apply the update from advisory RHSA-2026:24866, issued June 9, 2026. Red Hat notes that all previously released relevant errata must be applied first.
- Red Hat OpenShift AI: upgrade to 3.3.4 as described in advisory RHSA-2026:30056, issued June 25, 2026.
- After updating, rotate the LiteLLM master key and the API keys for the AI services the gateway uses. Since the flaw is being exploited, assume they may have leaked.
With a pip installation, the update looks like this (drop the proxy extra if you installed without it):
pip install --upgrade "litellm[proxy]"
As a general stopgap, not an official vendor workaround, you can block /guardrails/test_custom_code on the reverse proxy in front of LiteLLM if you do not use that feature. Also revoke unused keys and accounts, because the attack requires a login.
What if you may already be compromised
Neither NVD nor Red Hat lists specific indicators of compromise. Since EUVD lists the flaw as exploited, it is worth checking these places:
- LiteLLM and reverse proxy access logs: requests to
/guardrails/test_custom_code, especially from unknown IP addresses or with keys that have no reason to use that feature - unknown keys, users or teams in the LiteLLM admin interface
- unexpected processes, new files or outbound connections on the LiteLLM server or container
- billing with your AI providers: an unusual spike in usage may mean stolen keys
This command searches the nginx logs, including older compressed files. For Apache, use /var/log/apache2/ or /var/log/httpd/ instead:
zgrep -F "/guardrails/test_custom_code" /var/log/nginx/access.log*
If LiteLLM runs in Docker, search the container output too. Do this before you recreate the container, otherwise these logs are lost:
docker logs CONTAINER_NAME 2>&1 | grep -F "/guardrails/test_custom_code"
An empty result is no guarantee, because injected code often leaves no trace in regular logs. If you find suspicious requests or unknown accounts, disconnect the server from the network, preserve the logs and bring in an incident response specialist. They can assess whether the attacker moved further into your network.