Hunting LLMjacking: How to Check Your LiteLLM Gateway After CVE-2026-40217 Hit the KEV

One guardrail endpoint, a root shell, and every provider key you own. Here is how to find out if someone got there first.

Featured image

An AI gateway is a strange piece of infrastructure. It looks like a small developer convenience: one endpoint that routes requests to OpenAI, Anthropic, Bedrock, Vertex and the rest. In practice it is a vault. It stores every upstream provider key your company pays for, a master key, a database full of virtual keys and spend records, and often the cloud credentials of the container it runs in.

On 18 November 2026 CISA added CVE-2026-40217, a sandbox escape in the open-source LiteLLM proxy, to its Known Exploited Vulnerabilities (KEV) catalog. US federal agencies must fix it by 2 December 2026. Two weeks earlier, Google Threat Intelligence Group (GTIG) and Mandiant described how a criminal cluster turned bought, low-privilege LiteLLM keys into full PROXY_ADMIN credentials as part of LLMjacking campaigns. That is the theft and resale of enterprise AI access. Some victims ran up more than USD 100,000 in a single day.

This is a practical hunt guide. If your team runs LiteLLM, or any self-hosted LLM gateway, the checks below will help you answer two questions with evidence: are we vulnerable? and has anyone already been in?

TL;DR / Key takeaways

  • What it is: POST /guardrails/test_custom_code ran user-supplied Python inside a hand-rolled sandbox that could be escaped with bytecode tricks. Code then runs inside the proxy process, which is root in the default Docker image. Affected: litellm >= 1.81.8, < 1.83.10.
  • Patch target: the GitHub advisory’s metadata says 1.83.10, but its text says 1.83.11. Obsidian Security and the Cloud Security Alliance (CSA) recommend 1.83.14-stable or later, which also fixes the privilege-escalation chain (CVE-2026-47101 / CVE-2026-47102). Never install the backdoored 1.107.0 release.
  • Real-world abuse is about money: GTIG ties LiteLLM exploitation to LLMjacking. Watch for single-token “key validation” requests (max_tokens=1), sudden new proxy_admin users, unfamiliar guardrails or callbacks, and spend spikes.
  • Blocking the test endpoint is not enough. Obsidian found that the production POST /guardrails and PUT /guardrails/{id} routes also reached exec() on vulnerable builds.
  • If a vulnerable build was reachable by more than a handful of trusted people, rotate everything: provider keys, master key, database password, virtual keys and the container’s cloud IAM credentials.

Timeline

Date (2026) Event
13 Feb X41 D-Sec finds the guardrail sandbox escape.
8 Apr X41 publishes advisory X41-2026-001 before a vendor patch exists. CVE-2026-40217 follows on 10 April.
22–25 Apr LiteLLM ships v1.83.10-stable (sandbox replaced with RestrictedPython) and then v1.83.14-stable.
11 Jun Obsidian Security publishes a chain: two escalation bugs take a default internal_user to proxy_admin, and CVE-2026-40217 turns that into code execution.
21 Oct A malicious litellm==1.107.0 and matching Docker tags serve a credential stealer for a few hours.
2 Nov GTIG/Mandiant publish their LLMjacking report, naming CVE-2026-40217.
18 Nov CISA adds CVE-2026-40217 to KEV. Federal due date: 2 December.

This is LiteLLM’s fourth KEV entry this year, after CVE-2026-42208 (SQL injection, May), CVE-2026-42271 (MCP test endpoint command injection, June) and CVE-2026-59822 (MCP auth bypass, September). Attackers clearly have this product on their list.

How the attack works (conceptually)

The flaw. LiteLLM lets admins write custom-code guardrails: small Python functions that inspect prompts and responses. A test endpoint ran that code in a sandbox that filtered the source text with regular expressions. According to X41, an attacker could build blocked names such as __import__ at runtime and rewrite the function’s code object, so it reached OS commands even though the regex filter never saw a forbidden word. The fix swaps in RestrictedPython. Even so, RestrictedPython’s own documentation says it “is not a sandbox system”, so treat it as one layer of defence, not a hard isolation boundary.

Who can reach it. The vendor says that in default configurations you need a proxy-admin credential, and rates it CVSS v4 5.9. X41 scores it 8.7, on the assumption that a low-privileged user can get there. The Obsidian chain shows why the lower bar is realistic. CVE-2026-47101 let key creation set unrestricted allowed_routes, and CVE-2026-47102 let a user give themselves the proxy_admin role. Put the three together and any ordinary internal user, or anyone who buys one of their keys, can get a root shell.

What attackers did with it. GTIG describes a split criminal economy. Initial-access crews harvest keys from GitHub repos, logs and misconfigured cloud accounts. They check that the keys work with tiny max_tokens=1 requests that stay under volume alerts, then sell “pre-validated” access. Downstream “LLM Mixers” proxy and resell it. One service, Jet Night, offered “unlimited” tokens for about USD 60 a month and “passed nearly one million dollars in token costs to the victim organization.” A follow-on cluster bought LiteLLM virtual keys and escalated them to PROXY_ADMIN.

One discrepancy to be aware of: GTIG’s 2 November report describes CVE-2026-40217 as a “user ID rebind” in /key/regenerate. The vendor, X41, Obsidian and CISA describe it as the guardrail code-execution bug, and Obsidian assigns the /key/regenerate abuse to CVE-2026-47101. CSA says this “has not been publicly reconciled” and infers that the intrusions used the full chain. For defenders the practical answer is the same: hunt for the whole chain, not one endpoint.

Am I affected?

You should run this hunt if any of the following apply:

A clean result from the version check does not mean you were never exposed. The vulnerable window ran from at least February to late April for anyone who upgraded promptly, and much longer for anyone who did not.

Step 1: Find every gateway and its real version

Check the version inside the running container, not the chart or manifest. Run find before pip show: on a poisoned image, starting Python could itself run malware (the 1.107.0 backdoor used .pth start-up hooks).

~|#| Docker: list LiteLLM containers, then read the installed dist~|-|info name
docker ps ~|-|~|-|format '{{.Names}}\t{{.Image}}' | grep ~|-|i litellm
docker exec ~|<|container> sh ~|-|c "find / ~|-|maxdepth 7 ~|-|type d ~|-|name 'litellm~|-|*.dist~|-|info' 2>/dev/null"

~|#| Kubernetes: images in use, then the version inside the pod
kubectl get pods ~|-|A ~|-|o jsonpath~|=|'{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}' | grep ~|-|i litellm
kubectl exec ~|-|n ~|<|ns> ~|<|pod> ~|-|~|-| sh ~|-|c "find / ~|-|maxdepth 7 ~|-|type d ~|-|name 'litellm~|-|*.dist~|-|info' 2>/dev/null"

~|#| Supply~|-|chain leftovers from the October incident
docker exec ~|<|container> sh ~|-|c "find / \( ~|-|name 'cook.pth' ~|-|o ~|-|name 'cook.py' ~|-|o ~|-|name 'litellm~|-|1.107.0.dist~|-|info' \) 2>/dev/null; ls ~|-|l /tmp/remote_code_loader.lock 2>/dev/null"

Don’t forget developer laptops, CI runners and notebook servers, where pip install litellm[proxy] is a one-liner. Search your dependency manifests too (requirements*.txt, poetry.lock, uv.lock).

Step 2: Hunt the HTTP logs for the attack chain

LiteLLM normally sits behind nginx, an ingress controller or a cloud load balancer. Those access logs are your best record of the attack path. Start with a quick grep:

grep ~|-|E 'POST /guardrails/test_custom_code|(POST|PUT) /guardrails|/user/(update|bulk_update)|/key/(generate|update|regenerate)' \
  /var/log/nginx/access.log* | awk '{print $1, $4, $6, $7, $9}' | sort | uniq ~|-|c | sort ~|-|rn

For a SIEM, here is the same logic in Splunk (adjust the index and field names to your web log source):

index~|=|web sourcetype IN ("nginx:plus:kv","access_combined") host~|=|*litellm*
  (uri_path~|=|"/guardrails/test_custom_code" OR uri_path~|=|"/guardrails*"
   OR uri_path~|=|"/user/update" OR uri_path~|=|"/user/bulk_update"
   OR uri_path~|=|"/key/generate" OR uri_path~|=|"/key/update" OR uri_path~|=|"/key/regenerate")
  method IN ("POST","PUT")
| stats count min(_time) as first max(_time) as last values(uri_path) as paths by clientip, http_user_agent
| convert ctime(first) ctime(last)
| sort ~|-| count

And a generic Sigma rule you can convert for Sentinel, Elastic or others:

title: LiteLLM Guardrail Code Execution or Role Escalation Endpoint Access
id: 6f1d2c4e~|-|9b1a~|-|4d77~|-|8a52~|-|3e0c1f2a7b90
status: experimental
description: Detects requests to LiteLLM endpoints abused in the CVE~|-|2026~|-|40217 / CVE~|-|2026~|-|47101 / CVE~|-|2026~|-|47102 chain
references:
  ~|-| https://github.com/BerriAI/litellm/security/advisories/GHSA~|-|wxxx~|-|gvqv~|-|xp7p
logsource:
  category: webserver
detection:
  test_endpoint:
    cs~|-|uri~|-|stem|endswith: '/guardrails/test_custom_code'
  guardrail_write:
    cs~|-|method: ['POST', 'PUT']
    cs~|-|uri~|-|stem|contains: '/guardrails'
  role_change:
    cs~|-|method: 'POST'
    cs~|-|uri~|-|stem|endswith: ['/user/update', '/user/bulk_update']
  condition: test_endpoint or guardrail_write or role_change
falsepositives:
  ~|-| Legitimate administrators creating guardrails or changing roles (verify against change tickets)
level: high
tags:
  ~|-| attack.initial~|-|access
  ~|-| attack.t1190
  ~|-| attack.privilege~|-|escalation

How to triage hits: any call to test_custom_code that you cannot tie to a named teammate is a red flag. Role changes and guardrail writes should match change tickets. Pay special attention to source IPs that also send ordinary inference traffic: that is a virtual-key holder probing admin routes.

Step 3: Hunt the LiteLLM database

LiteLLM keeps its state in PostgreSQL. These read-only queries match the schema shipped in 1.83.x. Run them on a snapshot or read replica if you suspect compromise, so you don’t change evidence.

~|-|~|-| 1. Every admin. Compare against the people who actually operate the gateway.
SELECT user_id, user_alias, user_email, user_role, created_at, updated_at
FROM "LiteLLM_UserTable"
WHERE user_role IN ('proxy_admin', 'proxy_admin_viewer', 'org_admin')
ORDER BY updated_at DESC NULLS LAST;

~|-|~|-| 2. Virtual keys with broad or admin route access (CVE~|-|2026~|-|47101 abuse)
SELECT key_alias, user_id, team_id, allowed_routes, created_by, updated_by,
       created_at, updated_at, last_active
FROM "LiteLLM_VerificationToken"
WHERE allowed_routes IS NOT NULL AND cardinality(allowed_routes) > 0
ORDER BY updated_at DESC NULLS LAST;

~|-|~|-| 3. Custom~|-|code guardrails: read every line of code returned
SELECT guardrail_id, guardrail_name, created_at, updated_at,
       litellm_params~|-|>>'custom_code' AS code
FROM "LiteLLM_GuardrailsTable"
WHERE litellm_params~|-|>>'guardrail' ~|=| 'custom_code'
ORDER BY updated_at DESC;

~|-|~|-| 4. Models whose api_base points somewhere you do not recognise (traffic redirection)
SELECT model_name, litellm_params~|-|>>'api_base' AS api_base, created_by, updated_by, updated_at
FROM "LiteLLM_ProxyModelTable"
ORDER BY updated_at DESC;

If you hold an Enterprise licence with audit logging on, LiteLLM_AuditLog records who changed what. Without a licence, the docs say no audit logs are written:

SELECT updated_at, changed_by, changed_by_api_key, action, table_name, object_id, updated_values
FROM "LiteLLM_AuditLog"
WHERE table_name IN ('LiteLLM_UserTable', 'LiteLLM_VerificationToken')
  AND updated_at > now() ~|-| interval '120 days'
ORDER BY updated_at DESC;

Also read litellm_settings.callbacks in config.yaml. CSA research shows that malicious callbacks and guardrails can persist across upgrades, and that callbacks may not appear in the admin UI.

Step 4: Hunt for key-validation sweeps and abnormal spend

GTIG advises monitoring gateway logs “for anomalous, low-volume requests (such as max_tokens=1 or zero-temperature pings).” In LiteLLM, the LiteLLM_SpendLogs table lets you approximate that by looking for keys that send lots of one-token completions, or that suddenly appear from new IPs:

~|-|~|-| Keys making many tiny "does this work?" calls in the last 30 days
SELECT api_key, requester_ip_address, model,
       count(*) AS calls,
       sum(CASE WHEN completion_tokens ~|<|~|=| 1 THEN 1 ELSE 0 END) AS one_token_calls,
       min("startTime") AS first_seen, max("startTime") AS last_seen
FROM "LiteLLM_SpendLogs"
WHERE "startTime" > now() ~|-| interval '30 days'
GROUP BY api_key, requester_ip_address, model
HAVING sum(CASE WHEN completion_tokens ~|<|~|=| 1 THEN 1 ELSE 0 END) >~|=| 20
ORDER BY one_token_calls DESC;

~|-|~|-| Daily spend per key: look for a sudden step change
SELECT date_trunc('day', "startTime") AS day, api_key, round(sum(spend)::numeric, 2) AS usd
FROM "LiteLLM_SpendLogs"
WHERE "startTime" > now() ~|-| interval '60 days'
GROUP BY 1, 2
ORDER BY usd DESC
LIMIT 50;

(The api_key column holds a hashed token, so join it to LiteLLM_VerificationToken.token to get the key alias.)

Step 5: Hunt at the cloud providers

If the gateway’s provider keys or container credentials were stolen, the abuse shows up upstream, often in accounts where AI services were never switched on. GTIG says defenders should “treat any unauthorized enablement as a critical security event”, and that disabling model-invocation logging by non-IaC principals “should be treated as high severity.”

AWS (CloudTrail) in Splunk:

index~|=|aws sourcetype~|=|aws:cloudtrail eventSource~|=|"bedrock.amazonaws.com"
  eventName IN ("PutUseCaseForModelAccess","CreateFoundationModelAgreement",
                "PutModelInvocationLoggingConfiguration","DeleteModelInvocationLoggingConfiguration",
                "ListFoundationModels","GetFoundationModelAvailability")
| stats count values(eventName) as events values(userAgent) as agents values(sourceIPAddress) as ips
        by userIdentity.arn, awsRegion
| sort ~|-| count

Azure OpenAI / Cognitive Services (Sentinel KQL):

AzureActivity
| where TimeGenerated > ago(30d)
| where OperationNameValue has_any (
    "MICROSOFT.COGNITIVESERVICES/ACCOUNTS/DEPLOYMENTS/WRITE",
    "MICROSOFT.INSIGHTS/DIAGNOSTICSETTINGS/DELETE",
    "MICROSOFT.INSIGHTS/DIAGNOSTICSETTINGS/WRITE")
| project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, ResourceGroup, _ResourceId, ActivityStatusValue
| order by TimeGenerated desc

Google Cloud: alert on google.api.serviceusage.v1.ServiceUsage.EnableService for aiplatform.googleapis.com, and on new service-account keys. GTIG notes that Vertex inference calls sit in Data Access logs, which are off by default, so turn them on for projects that use AI.

Finally, check billing. GTIG says LLMjacking can generate huge charges “in a matter of hours”, so a spend alert is often your fastest detector. GTIG published two mixer domains as indicators, jet-night[.]com and newapi[.]pro. Search your DNS and proxy logs for them, but don’t rely on them: the operators rotate infrastructure.

Step 6: Respond and harden

Immediate (today)

  1. Upgrade every instance to 1.83.14-stable or later (not 1.107.0), pinned by version and image digest, never a floating tag.
  2. If you can’t upgrade yet, block POST /guardrails/test_custom_code at the reverse proxy, and limit /guardrails, /user/* and /key/* management routes to an admin network:

    location ~|=| /guardrails/test_custom_code { return 403; }
    location ~ ^/(guardrails|user|key|team|model)/ {
        allow 10.20.0.0/24;   ~|#| admin VPN only
        deny all;
        proxy_pass http://litellm:4000;
    }
    
  3. Take the admin UI and management API off the internet.
  4. Run the Step 3 queries and remove any admin, key, guardrail, callback or api_base you can’t account for. Take a snapshot first.

This week

  1. If a vulnerable build served more than a few trusted users, rotate in this order: provider keys (OpenAI, Anthropic, Gemini, Azure, Bedrock), LITELLM_MASTER_KEY, the database password, all virtual keys, then the container’s cloud IAM role and any service accounts created since. Do this even if logs look clean, because logs may be incomplete.
  2. Set spend caps and per-model quotas at the provider, outside the gateway, so a compromised gateway cannot spend without limit.
  3. Run the container as a non-root user and mount only the secrets it needs.

Longer term

  1. Treat AI gateways as Tier-0 assets, alongside identity providers and secret stores: same patch SLAs, the same access reviews and the same monitoring.
  2. Replace the shared master key with named admin accounts and SSO, and give virtual keys the fewest routes, models and budget they need.
  3. Prefer declarative guardrail policies over arbitrary code, or run custom code in a separate, isolated service.
  4. Ship gateway access logs, role changes and spend data to your SIEM, and set baselines for how often they normally change.

OffensioX perspective

The lesson of this year’s LiteLLM run is not “LiteLLM is bad.” Four KEV entries, a PyPI compromise and a backdoored release all show something else: AI gateways have become high-value targets, and many teams still deploy them like hobby projects. They go up quickly to unblock developers, sit on the default root container with a shared master key, follow latest, and nobody owns them in the asset register. Meanwhile, as GTIG’s research shows, criminals have built a supply chain that turns one leaked key into a resold subscription within hours. The irony here is sharp: the bug lived inside a safety feature. Any product that runs user-written code, even code labelled “guardrail”, needs the isolation you would give an untrusted plugin. We expect more of this as agent platforms, MCP servers and model routers multiply. For businesses in Pakistan and the wider region adopting AI quickly, the cost of LLMjacking lands in US dollars on a cloud bill, which makes it a finance problem as much as a security one.

If you’d like a second pair of eyes, OffensioX runs penetration tests and security assessments that include AI gateways, LLM applications and the cloud accounts behind them.

References