CVE-2026-40217: LiteLLM guardrail sandbox escape, now on CISA KEV
A sandbox escape in LiteLLM's custom-code guardrail test endpoint gives code execution on the AI gateway (CVSS 8.8, KEV). Exposure checks, key rotation, hunting and the fix.
LiteLLM is the open-source proxy a lot of teams put in front of their LLM providers: one OpenAI-compatible API, with virtual keys, budgets and logging, fanning out to OpenAI, Anthropic, Bedrock, Azure and the rest. That makes the box running it a credential vault. It holds every upstream provider key, plus the master key and the database that issues all the virtual keys. CVE-2026-40217 is code execution on that box. It was disclosed in April, but CISA only added it to the KEV catalog on 18 November 2026, so plenty of instances that were “patch later” because it needs admin rights are now overdue.
Scope and ethics. This post covers architecture, exposure checks, detection and remediation for LiteLLM deployments you own or are authorized to assess. It contains no sandbox-escape code and no requests that trigger the bug. The only network check below is an unauthenticated request that confirms whether a route is reachable on your own proxy.
At a glance
| CVE | CVE-2026-40217 (GHSA-wxxx-gvqv-xp7p, X41-2026-001) |
| Severity | CVSS 3.1 8.8 High, AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H (NVD and GitHub advisory). The GitHub advisory also gives CVSS 4.0 7.5 with PR:H; X41 gives CVSS 4.0 8.7 with PR:L |
| CWE | CWE-420 Unprotected Alternate Channel, CWE-94 Code Injection (NVD); CWE-913 (GitHub advisory) |
| Affected | litellm 1.81.8 up to, not including, 1.83.10 (GitHub advisory and NVD CPE data) |
| Fixed in | 1.83.10 per the advisory’s structured data; the advisory text says 1.83.11. Because of related bugs (below), I’d target 1.83.14 or later, and ideally current |
| Exploited? | Yes, per CISA KEV (added 18 Nov 2026, federal due date 2 Dec 2026). I found no public report describing the attacks themselves |
| Auth / interaction | Requires a credential that can call the endpoint, which is a proxy-admin / master key in default configs / none |
Description: how the bug works
LiteLLM’s guardrails let you run checks on prompts and responses. One kind is a custom-code guardrail: an admin supplies Python that inspects or transforms traffic. To help admins write those, the proxy exposes POST /guardrails/test_custom_code, which runs the submitted Python on the server so you can see what it does.
Running user-supplied Python safely is very hard, and LiteLLM’s original approach was a hand-rolled sandbox. According to X41 D-Sec, who found the bug, the sandbox decided what was allowed by applying regex filters to the source text, blocking strings for dangerous attributes and built-ins. That’s the design flaw. The filter only sees the literal text you submit, while Python can build names at runtime and manipulate its own code objects. X41 showed that by rewriting CPython bytecode, submitted code can reach attributes the text filter never saw, giving arbitrary code execution in the proxy process. CSA’s later write-up adds that the guardrail code ran through exec() with built-ins still reachable.
That’s why CISA and NVD classify it as an unprotected alternate channel (CWE-420): a debug/test endpoint that offers a second route into server-side code execution next to the “real” guardrail path.
The fix, per the GitHub advisory, replaced the hand-rolled sandbox with RestrictedPython.
Impact
- Code execution as the LiteLLM process. In the default Docker image that’s root (GitHub advisory, X41).
- Secrets exposure. The process has every upstream provider API key, the LiteLLM master key and salt key, and the database connection string, usually as environment variables. Assume all of them are readable once code runs.
- Abuse of the AI estate. Stolen provider keys mean attacker-paid-by-you inference, access to fine-tuned models, files and assistants on those accounts, and a pivot into whatever cloud account the gateway runs in.
- Tampering. Someone with code execution on the gateway can alter guardrails, logging and routing, so it can read or modify the prompts and responses of every application behind it.
Prerequisites and the authentication question
Sources describe the privilege needed differently, so be careful:
- GitHub advisory (vendor): “Reaching the endpoint requires a proxy-admin credential in default configurations.” Its CVSS 4.0 vector says
PR:H. - NVD and the advisory’s CVSS 3.1 vector:
PR:L. NVD’s text just says “remote attackers”. - X41: analysis says “authenticated users” with
PR:L, but its workaround section says the endpoint “requires authentication with the master key”.
The practical answer is that admin access to LiteLLM is easier to get than it sounds:
- The Cloud Security Alliance documented a chain in which CVE-2026-47101 (virtual keys created with unvalidated
allowed_routes) and CVE-2026-47102 (users promoting their own role via/user/update) let a low-privilege user reach admin, with CVE-2026-40217 as the final step to code execution. CSA lists LiteLLM v1.83.14-stable as the fix for all three. - LiteLLM has had other KEV-listed bugs this year: CVE-2026-42208, a pre-auth SQL injection in API-key verification that exposes the key database (KEV, 8 May 2026), and CVE-2026-42271, command injection in the MCP test endpoints (KEV, 8 June 2026).
- Master keys tend to leak: they’re in
.envfiles, CI variables, Helm values and notebooks.
So treat this as reachable for anyone who can get any foothold on your proxy, not only your admins.
Identifying affected systems
Inventory every LiteLLM deployment, including the “temporary” ones on dev laptops and GPU boxes.
# 1) Python installs
pip show litellm 2>/dev/null | grep -E '^(Name|Version|Location)'
python3 -c "import importlib.metadata as m; print(m.version('litellm'))" 2>/dev/null
# 2) Containers: which LiteLLM images are running, and what version is inside?
docker ps --format '{{.ID}} {{.Image}}' | grep -i litellm | while read -r id img; do
echo -n "$img -> "; docker exec "$id" pip show litellm 2>/dev/null | awk '/^Version/{print $2}'
done
# 3) Kubernetes
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}{"\t"}{range .spec.containers[*]}{.image}{" "}{end}{"\n"}{end}' | grep -i litellm
# 4) Does the process run as root? (affects impact)
docker ps -q | xargs -r docker inspect --format '{{.Name}} user={{.Config.User}}' | grep -i litellm
Vulnerable range: 1.81.8 ≤ version < 1.83.10. Anything below 1.83.14 is also exposed to the related privilege-escalation bugs CSA describes.
Red Hat products bundle LiteLLM. NVD lists Ansible Automation Platform 2.0 up to 2.6-9, OpenShift AI 3.3 up to 3.3.4 and OpenShift Lightspeed as affected; see RHSA-2026:24866 and RHSA-2026:30056.
Is the endpoint reachable? On a proxy you own, send a request with no credentials and no body. You’re only checking routing and auth, not running anything:
# Expect 401/403 (route exists, auth enforced) or 404 (blocked at your proxy / not present).
# A 2xx here would mean auth isn't being enforced: investigate immediately.
curl -s -o /dev/null -w "test_custom_code: %{http_code}\n" \
-X POST https://litellm.internal.example.com/guardrails/test_custom_code
Also check where the admin API and UI are reachable from. If the proxy port (4000 by default) is open to the internet or to every workload in the cluster, fix that regardless of version.
Safe validation in an isolated lab
- In an isolated network namespace, run an image with a vulnerable version (anything from 1.81.8 to 1.83.9) and a current one with a throwaway master key and no real provider keys.
- Confirm your SCA tooling (Dependabot, Trivy, Grype, pip-audit) flags
litellmin the old image for GHSA-wxxx-gvqv-xp7p / CVE-2026-40217. If it doesn’t, check whether it scans Python packages inside container images. - Add the reverse-proxy block below in front of the old one and re-run the unauthenticated
curlabove. It should now return 403/404 at the proxy layer, never reaching LiteLLM. - Make a normal admin API call and confirm it lands in your SIEM with the key alias, source IP and route, which is what you’ll need for the hunt below.
Detection and threat hunting
No IOCs have been published for the November exploitation that put this on KEV, so hunt on behavior.
- Requests to the test endpoint. Search reverse-proxy, ingress and LiteLLM logs for
POST /guardrails/test_custom_code. Legitimate use should be rare and come from known admins. Calls from unexpected IPs, at odd hours or with large bodies are worth a look. - Neighboring endpoints from the same chain.
/user/updateand/user/bulk_updatecalls that change roles,/key/generateor key updates with unusualallowed_routes, and the MCP test routes/mcp-rest/test/connectionand/mcp-rest/test/tools/list. - Process lineage. The LiteLLM Python process (usually
uvicorn/python ... litellm) spawningsh,bash,curl,wget,ncorpython -c, or writing files under/tmp. In Kubernetes, watch for shells inside the LiteLLM pod that nokubectl execsession explains, and for unexpected outbound connections from the pod. - Environment and secret access. Reads of
/proc/<pid>/environ, the.envfile or mounted secrets by anything other than the main process. - API key use. This is the most important hunt for an AI gateway:
- In LiteLLM’s spend/usage logs, look for virtual keys used from new IPs, new models, or volumes far outside their history, and keys you don’t recognize.
- At each upstream provider (OpenAI, Anthropic, Azure, Bedrock, Vertex), review usage and audit logs for the keys the gateway holds. Calls that didn’t come through your gateway’s egress IPs mean the key has left the building.
- Watch for new provider-side assets: files, fine-tunes, assistants or batch jobs nobody created.
- Supply chain, separately. CSA notes that malicious
litellm1.82.7 and 1.82.8 were published to PyPI on 24 March 2026. If either was ever installed, treat the host’s secrets as compromised, independently of this CVE.
Remediation
- Upgrade LiteLLM. The advisory marks 1.83.10 as the first patched release (its text says 1.83.11). Given the related CVE-2026-47101/-47102/-42271 fixes, go to 1.83.14 or later, and preferably the current release. Rebuild and redeploy images; don’t just
pip installinside a running container. - Block the endpoint at the edge anyway. Even on fixed versions, few teams need to test guardrail code in production:
# nginx in front of LiteLLM location = /guardrails/test_custom_code { return 403; } - Rotate secrets if the proxy was on a vulnerable version and reachable by anyone beyond a small admin group:
- every upstream provider key the proxy holds,
- the LiteLLM master key and salt key (check LiteLLM’s docs before rotating the salt key, since it encrypts stored credentials),
- the database password and any cloud credentials in the environment,
- virtual keys issued to applications, prioritizing high-budget ones.
- Reduce blast radius. Run the container as a non-root user (X41 suggests
--user), keep the admin API and UI on a management network, use a secrets manager instead of plain env vars where you can, and set per-key budgets and rate limits so a stolen key is noisy. - Audit admins. Review who holds proxy-admin roles and the master key, and remove anything that shouldn’t be there.
Interim mitigation (if you can’t upgrade today)
Both the vendor and X41 give the same workaround: block POST /guardrails/test_custom_code at your reverse proxy or API gateway. Pair it with network restrictions on the admin interface and limiting master-key distribution. That narrows this specific route; it doesn’t fix the related privilege-escalation bugs, so keep the upgrade on the schedule.
References
- CVE-2026-40217, NVD · CISA KEV entry
- LiteLLM security advisory GHSA-wxxx-gvqv-xp7p · GitHub Advisory Database entry
- X41 D-Sec advisory X41-2026-001 (root cause, timeline)
- Cloud Security Alliance research note: LiteLLM AI gateway attack chain
- Red Hat CVE page
- LiteLLM v1.83.10-stable release
Verify every version against the vendor advisory before acting. Published 19 Nov 2026.