CVE-2026-40217: LiteLLM Arbitrary Code Execution via Bytecode Rewriting

LiteLLM through version 2026-04-08 allows low-privileged attackers to execute arbitrary code by submitting malicious bytecode to the /guardrails/test_custom_code endpoint. This is actively exploited and affects organizations using LiteLLM as a language model routing and guardrails middlewa

Share

LiteLLM is an open-source library that provides a unified API for accessing multiple large language models and includes guardrails for safety and content filtering. The vulnerability allows an attacker with low-level privileges (such as an authenticated user or internal service) to bypass guardrails by directly submitting malicious Python bytecode to a testing endpoint, which the application executes without proper validation.

CVECVE-2026-40217
SeverityHigh (CVSS 8.8)
Actively exploitedYes, listed in CISA's Known Exploited Vulnerabilities catalog on 18 Nov 2026
CISA remediation deadline2 Dec 2026
WeaknessCWE-420, CWE-94 (code injection)
Attack vectorNetwork
Privileges requiredLow
User interactionNone
Published10 Apr 2026

How the attack works

The /guardrails/test_custom_code endpoint accepts custom bytecode or compiled code objects for testing guardrail rules. An attacker with low privileges sends crafted bytecode that rewrites or bypasses the intended guardrail logic, or injects arbitrary Python code. LiteLLM loads and executes this bytecode without validation, allowing the attacker to run any code in the context of the LiteLLM process and gain access to underlying language models, cached credentials, or system resources.

Who is affected

Organizations running LiteLLM through version 2026-04-08 are affected. This includes enterprises using LiteLLM to manage and route requests to multiple LLM providers (OpenAI, Anthropic, Azure OpenAI, local models, etc.) as a central proxy or guardrails layer.

Affected products listed:

  • Litellm (up to and including 2026-04-08)

How to check if you're exposed

  • Determine LiteLLM version deployed; check pip list, requirements.txt, or the application startup logs for the version string
  • Review access logs for the /guardrails/test_custom_code endpoint; look for POST requests with custom bytecode or pickle-serialized objects from internal or low-privileged accounts
  • Monitor LiteLLM process logs and application error logs for unexpected Python bytecode compilation or deserialization errors
  • Inspect outbound connections from the LiteLLM service to language model APIs, file systems, or cloud credential endpoints that may indicate post-exploitation activity

How to fix it

  • Upgrade LiteLLM to a version after 2026-04-08 by running 'pip install --upgrade litellm' or updating your dependency manifest
  • If upgrade cannot be performed immediately, disable or remove the /guardrails/test_custom_code endpoint from your deployment configuration and restart the service
  • Review and rotate any API credentials (OpenAI, Anthropic, Azure, etc.) that may have been exposed through the LiteLLM service
  • Audit logs and cache for evidence of bytecode injection attempts or unusual model API calls; review LiteLLM audit trails for suspicious guardrail test submissions

If you can't patch yet

  • Restrict network access to the /guardrails/test_custom_code endpoint to internal IP ranges only; block external access via firewall or reverse proxy authentication
  • Implement role-based access control (RBAC) so that only administrators can access guardrail testing endpoints; prevent low-privileged users from reaching the endpoint
  • Deploy a Web Application Firewall (WAF) or API gateway that inspects POST bodies to the endpoint and blocks requests containing serialized Python objects or bytecode signatures

Need help checking your exposure or patching at scale? FutureOps InfoTech can help.

Read more