LiteLLM CVE-2026-40217 is a sandbox escape in the LiteLLM proxy's POST /guardrails/test_custom_code endpoint. It lets an attacker with admin-level API access run arbitrary code inside the proxy process, which runs as root in the default Docker image. It's fixed in LiteLLM 1.83.10, but you should be on 1.83.14 or later, because a published privilege-escalation chain lets an ordinary internal user reach that endpoint on anything older. CISA added it to the Known Exploited Vulnerabilities catalog on November 18, 2026, with a federal remediation deadline of December 2.

This guide explains what's vulnerable, how to check your version and exposure, what to look for if you were exposed, and a hardening checklist for self-hosted LLM gateways that I'd apply whether or not you were hit. An LLM gateway holds every provider API key your organization pays for, which makes it one of the most valuable boxes on your network.

What CVE-2026-40217 is

The vulnerability was found by X41 D-Sec, who reported it on February 13, 2026 and published advisory X41-2026-001 on April 8 after the disclosure embargo ran out. BerriAI's own advisory is GHSA-wxxx-gvqv-xp7p.

  • The endpoint: POST /guardrails/test_custom_code lets an admin test a custom-code guardrail by sending Python source to the proxy, which runs it.
  • The flaw: the "sandbox" was a hand-rolled regex deny-list over the source text. X41 bypassed it by building forbidden names from strings and rewriting CPython bytecode at runtime to reach unrestricted builtins, so no blocked token ever appears in the source.
  • The impact: arbitrary code execution as the proxy process. In ghcr.io/berriai/litellm's default configuration that's root inside the container, with every provider key, the database URL and the master key in its environment.
  • Severity: CVSS 3.1 8.8 (network, low complexity, low privileges) in the GitHub advisory. X41 scored it 8.7 under CVSS 4.0.
  • Affected: litellm 1.81.8 up to (but not including) 1.83.10, per the GitHub Advisory Database. The fix replaced the deny-list with RestrictedPython.

There's a small inconsistency in the advisory: its prose says "Fixed in 1.83.11" while its version metadata and release link point to 1.83.10. It doesn't matter in practice, because the version you actually want is higher.

Why "requires admin" is not reassuring

GitHub's advisory says reaching the endpoint "requires a proxy-admin credential in default configurations". In June 2026 Obsidian Security published a three-CVE chain that starts from internal_user, the default role for ordinary users who can call models and create their own virtual keys:

  1. CVE-2026-47101: an internal_user can mint a virtual key whose allowed_routes includes admin-only routes. Fully fixed in 1.83.14.
  2. CVE-2026-47102: that key calls /user/update and sets its own user_role to proxy_admin. Fixed in 1.83.10.
  3. CVE-2026-40217: as proxy admin, run code through the guardrail test endpoint.

Obsidian scores the chain 9.9 and calls v1.83.14-stable "the first release that contains the complete fix set for all three CVEs". So the realistic attacker isn't someone who already owns your master key. It's anyone you've issued a LiteLLM login or key to, or anyone who has stolen one.

Which LiteLLM version to run

Version CVE-2026-40217 Full chain (47101 + 47102 + 40217) Verdict
Below 1.81.8 Not in the affected range Other critical CVEs apply Upgrade
1.81.8 – 1.83.9 Vulnerable Vulnerable Upgrade now
1.83.10 – 1.83.13 Fixed 47101 still open Upgrade
1.83.14 and later Fixed Fixed Minimum acceptable
1.107.0 n/a n/a Compromised release, see below
Current release (1.112.0 on PyPI as of December 2, 2026) Fixed Fixed Target

Don't stop at 1.83.14. The GitHub Advisory Database lists a steady stream of LiteLLM fixes since April, including a critical authentication bypass through Host header injection (CVE-2026-49468, fixed in 1.84.0), an authenticated SSRF with provider-credential exfiltration (CVE-2026-84377, fixed in 1.88.6 and backported to several lines), an internal_user local file read (fixed in 1.95.0), and privilege escalation to proxy admin through salt-key reuse (CVE-2026-114612, fixed in 1.100.4 and later lines). A gateway pinned to an April release is exposed to most of them.

The October 21 supply-chain incident

When you upgrade, pin an exact version and verify it. On October 21, 2026, LiteLLM's release pipeline was compromised and a malicious 1.107.0 was published. According to LiteLLM's incident report, it was on PyPI from 11:39 to 13:23 UTC, and the Docker tags v1.107.0, latest, main-latest and main-stable pointed at compromised images from 11:46 UTC until 14:20 UTC (13:51 on GHCR). If anything pulled those during the window, follow that report: look for cook.pth and sitecustomize.py in site-packages, don't run pip in the affected environment first, rebuild, and rotate every provider key stored in the proxy database. The containment order in our compromised package runbook (isolate first, rotate from a clean machine) applies to PyPI as much as npm. Since November 15, 2026, LiteLLM signs releases with keyless cosign (more on verification below).

How to check your exposure

1. Find the running version

The unauthenticated /health/readiness endpoint no longer returns the version by default. Ask the runtime instead:

# Docker
docker exec litellm python -c "import importlib.metadata as m; print(m.version('litellm'))"

# Kubernetes, every pod with the app label
for p in $(kubectl get pods -n litellm -l app=litellm -o name); do
  printf '%s  ' "$p"
  kubectl exec -n litellm "$p" -- python -c "import importlib.metadata as m; print(m.version('litellm'))"
done

# Or the authenticated diagnostics endpoint
curl -s https://llm-gw.internal.example.com/health/readiness/details \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq .

Check what's actually running in each pod, not what your Helm values say. Image tags like main-stable are mutable, and the October incident showed why that matters.

2. Check whether the admin API is reachable from where it shouldn't be

From a network position an attacker would have (the internet, or a general corporate subnet), probe the endpoint without credentials:

curl -s -o /dev/null -w '%{http_code}\n' -X POST \
  https://llm-gw.example.com/guardrails/test_custom_code

A 401 or 403 from LiteLLM means the route is reachable and only authentication stands between an attacker and the chain above. What you want from untrusted networks is a 404 or a connection failure from your reverse proxy, because the management API shouldn't be routed there at all. Run the same test against /user/update, /key/generate and the Admin UI path /ui.

3. Hunt in the database

LiteLLM stores users, keys and guardrails in PostgreSQL. These queries use table and column names from LiteLLM's Prisma schema. I checked the SQL syntax with psql 16 against stand-in tables, not against a live LiteLLM database:

-- Who is a proxy admin, and when did that last change?
SELECT user_id, user_email, updated_at
FROM "LiteLLM_UserTable"
WHERE user_role = 'proxy_admin'
ORDER BY updated_at DESC;

-- Virtual keys with explicit allowed_routes (the CVE-2026-47101 pattern)
SELECT key_alias, user_id, allowed_routes, created_at
FROM "LiteLLM_VerificationToken"
WHERE cardinality(allowed_routes) > 0
ORDER BY created_at DESC;

-- Every guardrail registered on the proxy
SELECT guardrail_name, litellm_params->>'guardrail' AS guardrail_type, updated_at
FROM "LiteLLM_GuardrailsTable"
ORDER BY updated_at DESC;

-- If audit logging is enabled: recent admin changes
SELECT updated_at, changed_by, action, table_name, object_id
FROM "LiteLLM_AuditLog"
WHERE updated_at > now() - interval '90 days'
ORDER BY updated_at DESC
LIMIT 200;

Things that should worry you: a proxy_admin you didn't appoint, a key owned by a regular user whose allowed_routes includes /user/update or /key/*, or a custom-code guardrail nobody remembers writing. Obsidian also recommends auditing litellm_settings.callbacks in config.yaml (callbacks don't appear in the Admin UI) and checking the integrity of the deployed code, not just its configuration. In gateway access logs, look for requests to /guardrails/test_custom_code, /user/update, /user/bulk_update, /key/generate and /key/update from unexpected clients.

If you find any of these, treat the container as compromised. Rotate every provider API key the proxy held, the database password, the master key and all virtual keys, then redeploy from a verified image.

Hardening checklist for self-hosted LLM gateways

This checklist is LiteLLM-specific where the setting names matter, but the principles apply to any self-hosted LLM gateway. Most of it comes from LiteLLM's own security best practices and production checklist.

Split the inference API from the management API

This is the control that would have made CVE-2026-40217 a non-event for most deployments. Applications need a handful of inference routes. Nobody outside the platform team needs /key/*, /user/*, /guardrails/* or /ui. Publish only the inference routes, and serve the management surface on a separate hostname that's reachable only from an admin network:

# Public / application-facing vhost: inference routes only
location ~ ^/(v1/)?(chat/completions|completions|embeddings|models|responses|messages)$ {
    proxy_pass http://litellm_upstream;
}
location ~ ^/health/(liveliness|readiness)$ {
    proxy_pass http://litellm_upstream;
}
location / {
    return 404;
}
# Admin vhost (separate server block, bound to an internal address)
allow 10.20.0.0/24;   # platform team / jump hosts
deny all;
location ^~ /guardrails/test_custom_code { return 403; }   # belt and braces
location / { proxy_pass http://litellm_upstream; }

Adjust the route list to the APIs your applications actually call. LiteLLM also has an allowed_routes setting in general_settings that limits exposed routes inside the proxy, but its docs mark route controls as an Enterprise feature. The reverse-proxy split works on the open-source build and doesn't depend on LiteLLM getting its own authorization right, which is the whole lesson of this CVE chain. X41's advisory gives the same advice: block the endpoint at the reverse proxy and keep the management interface off untrusted networks.

Credentials and keys

  • The master key is an admin password, not an API key. Applications get scoped virtual keys, one per workload, so you can revoke one without breaking the rest. LITELLM_MASTER_KEY must start with sk- and belongs in a secret manager.
  • Turn off environment-credential login to the Admin UI. By default the UI accepts UI_USERNAME/UI_PASSWORD, or the master key when UI_PASSWORD is unset. That's a shared, permanent admin login. Create individual proxy_admin users (or connect SSO), confirm they can sign in, then set disable_env_credential_login: true.
  • Set LITELLM_SALT_KEY once and never change it. It encrypts stored provider credentials, and changing it after models are added makes them unreadable.
  • Rotate the master key carefully. LiteLLM's master key rotation guide warns that on versions before 1.112.0, calling POST /key/regenerate with new_master_key on a deployment that uses a salt key re-encrypts credentials under a key the proxy never decrypts with, which can brick the deployment. With a salt key set, rotation is just: change the secret, restart every instance. Back up the database first either way.
  • Keep the number of proxy admins small and review it on a schedule using the query above.

Configuration that closes common gaps

# config.yaml
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  disable_env_credential_login: true      # only after per-person admin accounts exist
  trusted_proxy_ranges: ["10.0.0.0/8"]    # your ingress CIDRs, or [] if clients connect directly
# Environment
LITELLM_MODE="PRODUCTION"   # disables loading credentials from a local .env file
NO_DOCS="True"              # hide the API reference at /
NO_OPENAPI="True"           # hide /openapi.json (NO_DOCS alone leaves it readable)
LITELLM_NON_ROOT="true"     # pair with a non-root securityContext

trusted_proxy_ranges matters more than it looks. Without it, LiteLLM's Admin UI sign-in rate limit only works per username, not per source address, so password spraying from one IP isn't throttled. Run Redis if you have more than one worker, or each worker keeps its own count.

Container and supply chain

  • Don't run as root. Use LITELLM_NON_ROOT="true" with runAsNonRoot: true, runAsUser: 101, readOnlyRootFilesystem: true and capabilities.drop: [ALL], as LiteLLM's production guide describes. X41 makes the same point: root in the container turns code execution into full container compromise.
  • Pin by digest and verify signatures. Releases since v1.111.0-dev.3 (November 15, 2026) are signed with keyless cosign. Verify against LiteLLM's exact release-workflow identity, not a regex:
cosign verify \
  --certificate-identity https://github.com/BerriAI/project-releaser/.github/workflows/release.yml@refs/heads/main \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  ghcr.io/berriai/litellm:v1.112.0

Use the tag you actually deploy. Releases published before November 15 were signed with a stored key instead, and LiteLLM's Docker image security guide lists which key applies to which release.

Network and egress

  • Keep the gateway on a private network. Let the gateway, not the applications, hold provider keys.
  • Restrict egress to the provider endpoints you use, plus your logging and observability sinks. Several 2026 LiteLLM CVEs were SSRF bugs, and a stolen-credential payload has to call home. A default-deny egress policy limits both.
  • Keep TLS verification on for gateway-to-provider traffic, and use a custom CA bundle rather than turning verification off.

If you're deciding what sits behind the gateway, our threat modeling guide for LLM applications is a good structure for mapping these trust boundaries. Gateway guardrails don't replace application-level defenses against prompt injection either, which our prompt injection prevention guide covers.

Frequently Asked Questions

Is CVE-2026-40217 being exploited?

Yes. CISA added CVE-2026-40217 to its Known Exploited Vulnerabilities catalog on November 18, 2026, with a remediation due date of December 2, 2026 for US federal agencies. A public proof-of-concept technique was described in X41's April 2026 advisory.

What version of LiteLLM fixes CVE-2026-40217?

The sandbox escape is fixed in 1.83.10, where the regex filter was replaced with RestrictedPython. Run at least 1.83.14, the first release that fixes the full privilege-escalation chain (CVE-2026-47101, CVE-2026-47102 and CVE-2026-40217), and preferably the current release, because many later LiteLLM CVEs are fixed only in newer versions.

Do I need admin access to exploit CVE-2026-40217?

In default configurations the endpoint needs a proxy-admin credential. On versions before 1.83.14, though, a default internal_user can escalate to proxy admin through CVE-2026-47101 and CVE-2026-47102, so any issued user account or stolen virtual key can be enough.

Can I block the vulnerable endpoint without upgrading?

Yes, as a stopgap. Both BerriAI and X41 suggest blocking POST /guardrails/test_custom_code at your reverse proxy or API gateway. A stronger version is to route only inference endpoints to application networks and keep the whole management API on an admin-only network. Still upgrade, because the same versions have other serious bugs.

Was I affected by the LiteLLM 1.107.0 compromise?

Only if you installed litellm==1.107.0 from PyPI between 11:39 and 13:23 UTC on October 21, 2026, or pulled the v1.107.0, latest, main-latest or main-stable Docker tags during the compromise window that day. If so, follow LiteLLM's incident report: rebuild the environment and rotate every credential the proxy could reach.

Should the LiteLLM Admin UI be exposed to the internet?

No. Put the Admin UI and management API behind an admin-only network or VPN, use individual admin accounts or SSO instead of the master key, and set disable_env_credential_login: true once those accounts exist.

Conclusion

CVE-2026-40217 is a gateway bug with a lesson that applies beyond LiteLLM: an endpoint that executes admin-supplied code is only as safe as every path to admin, and in LiteLLM's case one of those paths started at an ordinary user account. Upgrade to the current release (1.83.14 at an absolute minimum, and not 1.107.0), check your proxy admins, keys and guardrails for anything you didn't create, split inference routes from the management API at the reverse proxy, and run the container as non-root from a signature-verified image. If you're comparing gateway or router options while you're at it, our overview of AI model routers is a starting point. If you self-host the models behind the gateway, the vLLM multi-user serving guide covers that side.