Advisory

CVE-2026-40217: BerriAI LiteLLM Remote Code Execution via Bytecode Rewriting (CVSS 8.8 HIGH)

A high-severity vulnerability in BerriAI LiteLLM allows authenticated remote attackers to execute arbitrary code by abusing an unprotected endpoint that accepts and rewrites Python bytecode. The flaw is actively tracked in the CISA Known Exploited Vulnerabilities catalog, making rapid remediation essential.

TL;DR: Apply vendor-issued mitigations immediately or discontinue use of the affected LiteLLM deployment if no fix is available; the vulnerability is confirmed exploited in the wild per CISA KEV and carries a CVSS score of 8.8 (HIGH).

What Is the Vulnerability?

CVE-2026-40217 is a remote code execution (RCE) vulnerability in BerriAI LiteLLM, an open-source LLM API gateway used to route and manage requests to large language model providers. The National Vulnerability Database (NVD) describes it as follows:

"LiteLLM through 2026-04-08 allows remote attackers to execute arbitrary code via bytecode rewriting at the /guardrails/test_custom_code URI."

Two weaknesses underpin the issue:

  • CWE-420 – Unprotected Alternate Channel: The /guardrails/test_custom_code endpoint functions as an alternate execution channel that lacks adequate access controls, allowing a low-privileged authenticated user to reach functionality that should be tightly restricted or unavailable externally.
  • CWE-94 – Improper Control of Code Generation (Code Injection): Input supplied to the endpoint is processed through bytecode rewriting, meaning attacker-controlled Python bytecode can be injected and subsequently executed on the host running LiteLLM.

The combination is particularly dangerous: the alternate channel bypasses normal guardrail protections, while the code injection primitive turns that bypass into full arbitrary code execution on the server.

Who and What Is Affected?

According to NVD, all versions of LiteLLM up to and including the build released on 2026-04-08 are affected. Organizations that may be exposed include:

  • Development and production teams using LiteLLM as an API proxy or gateway to commercial or self-hosted LLM providers.
  • MLOps and AI platform teams that have deployed LiteLLM in internal infrastructure or cloud environments where the management interface is network-accessible.
  • Any deployment where the /guardrails/test_custom_code route is reachable by authenticated users — even those with minimal privileges, as the CVSS vector reflects low required privileges (PR:L).

The CVSS 3.1 vector AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H tells us:

AttributeValueMeaning
Attack VectorNetworkExploitable remotely over the network
Attack ComplexityLowNo special conditions or race windows required
Privileges RequiredLowA basic authenticated account is sufficient
User InteractionNoneNo victim action needed
ScopeUnchangedImpact confined to the vulnerable component
Confidentiality / Integrity / AvailabilityHigh / High / HighFull compromise of all three pillars

Potential Impact

Successful exploitation grants an attacker arbitrary code execution with the privileges of the LiteLLM process. Depending on deployment configuration, that can translate to:

  • Data exfiltration: Access to API keys, model credentials, prompt logs, and any secrets in the process environment or reachable file system.
  • Lateral movement: A compromised LiteLLM host sitting inside a cloud or on-premises network can serve as a pivot point to reach adjacent services, databases, or identity providers.
  • Availability disruption: Attackers can crash, reconfigure, or persistently backdoor the gateway, disrupting all downstream LLM-dependent workflows.
  • Supply chain risk: Because LiteLLM proxies traffic to external LLM APIs, a compromised instance could tamper with prompts or responses in transit, introducing integrity risks for applications built on top of it.

CISA's KEV entry confirms this vulnerability is being actively exploited, elevating it beyond a theoretical risk. CISA added this vulnerability to the KEV catalog on 2026-11-18.

What to Do Right Now

CISA's required action for KEV entries is clear: apply mitigations in accordance with vendor instructions or, if mitigations are unavailable, discontinue use of the product. The following steps reflect that guidance:

  1. Inventory all LiteLLM deployments. Identify every instance running a version built on or before 2026-04-08 — including development, staging, and production environments.
  2. Apply vendor patches immediately. Check BerriAI's official release channels and security advisories for a patched version. Prioritize deployments that are internet-facing or reachable by external users.
  3. Restrict access to /guardrails/test_custom_code now. If patching cannot happen immediately, use network controls (firewall rules, reverse-proxy deny rules, or authentication middleware) to block unauthenticated and low-privileged access to this route as an interim measure.
  4. Rotate exposed credentials. Any API keys, LLM provider tokens, or secrets accessible to the LiteLLM process should be treated as potentially compromised and rotated.
  5. Review access logs. Examine web server and application logs for unexpected POST requests to /guardrails/test_custom_code prior to patching. Anomalous activity may indicate prior exploitation.
  6. Follow BOD 26-04 timelines. Federal agencies and entities subject to CISA's Binding Operational Directive 26-04 must adhere to its patching deadlines. Consult the directive directly for authoritative timelines applicable to internet-facing versus internal assets.

Primary references for remediation guidance:

How External Testing Surfaces This Exposure

Point-in-time external security assessments can help organizations understand whether their LiteLLM deployment is reachable from outside their intended network perimeter and whether the vulnerable endpoint responds to unauthenticated or low-privilege probes. Specifically, an external test can determine:

  • Whether the LiteLLM administrative or API interface is unintentionally exposed to the internet or untrusted network segments.
  • Whether the /guardrails/test_custom_code route is accessible without the expected access controls in place.
  • Whether the deployment version falls within the affected range identified by NVD.
  • Whether network segmentation effectively limits which users or systems can reach the LiteLLM host.

Understanding your exposure boundary is a prerequisite for prioritizing remediation. Even if internal patch management is underway, an externally reachable unpatched instance represents the highest-risk scenario given confirmed active exploitation.

Sources & further reading: NVD CVE-2026-40217 and the CISA KEV catalog are the authority on affected and fixed versions. Vendor/independent analysis: x41-dsec.de, access.redhat.com, access.redhat.com, access.redhat.com. This advisory contains no exploit code.

Frequently asked questions

Which versions of LiteLLM are affected by CVE-2026-40217?

According to NVD, LiteLLM through the version released on 2026-04-08 is affected. Any deployment running a build on or before that date should be treated as vulnerable until a patched version confirmed by BerriAI is applied.

Does an attacker need admin credentials to exploit this vulnerability?

No. The CVSS vector for CVE-2026-40217 specifies 'Privileges Required: Low,' meaning a basic authenticated account is sufficient. No elevated or administrative privileges are required, which significantly broadens the potential attacker pool.

Is this vulnerability being actively exploited?

Yes. CISA added CVE-2026-40217 to its Known Exploited Vulnerabilities catalog on 2026-11-18, confirming active exploitation. Organizations should treat this as a priority remediation item and not assume they are safe simply because they have not observed signs of compromise.

What is a bytecode rewriting attack and why is it dangerous in this context?

Python bytecode rewriting involves manipulating compiled Python code objects to change program behavior at runtime. When an endpoint like /guardrails/test_custom_code accepts attacker-supplied input that influences bytecode execution, an attacker can craft that input to run arbitrary instructions on the server — effectively turning the endpoint into a remote shell. The lack of adequate access controls on this endpoint (CWE-420) makes the injection point (CWE-94) reachable by low-privileged users.