# CVE-2026-59821: BerriAI LiteLLM code injection in Custom Code Guardrails

Source: https://junglewise.ai/threats/cve-2026-59821-berriai-litellm-code-injection-in-custom-code-guardrails  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-07-08. Updated: 2026-07-22  
License: CC BY 4.0 with a link back

CVE-2026-59821 · Severity: medium · CVSS 4 · Published 2026-07-08

LiteLLM, a tool used to manage and proxy various AI models, contains a vulnerability in its 'Custom Code Guardrails' feature. This flaw allows users with administrative access to bypass security sandboxing and execute arbitrary Python code on the server. If a master key is not configured, even non-administrative users might be able to exploit this, potentially leading to the theft of sensitive API keys and service disruption.

Technologies: [Berriai LiteLLM](https://junglewise.ai/threats/technologies/litellm), [litellm (PyPI)](https://junglewise.ai/threats/technologies/pypi-litellm). Vendors: [Berriai](https://junglewise.ai/threats/vendors/berriai), [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2026-59821 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-59821 being exploited in the wild.

**How severe is CVE-2026-59821?** Medium severity, with a CVSS score of 4, published 8 July 2026.

**Which products and versions are affected?** Berriai LiteLLM < 1.82.0, < 1.82.0-stable; litellm (PyPI) ECOSYSTEM:introduced=0,fixed=1.82.0.

**Is there a fix for CVE-2026-59821?** Yes. litellm (PyPI): upgrade to 1.82.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-59821 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2026-59821?** Check whether you run Berriai LiteLLM or litellm (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- litellm (PyPI): upgrade to 1.82.0 or later

  ```sh
  pip install "litellm>=1.82.0"
  ```


## Technical details

A code injection vulnerability exists in LiteLLM's production endpoints for creating and updating Custom Code Guardrails (POST /guardrails and PUT /guardrails/{guardrail_id}). Unlike the test endpoint, these production paths failed to apply proper sandboxing and validation to user-submitted Python code. An attacker with administrative privileges—or a standard user in deployments where LITELLM_MASTER_KEY is not set—can execute arbitrary Python code within the LiteLLM proxy container. This can lead to full container compromise and the exposure of environment variables and secrets. The issue is resolved in version 1.82.0-stable.

## Affected products

- BerriAI litellm < 1.82.0

## Identifiers

- CVE-2026-59821
- GHSA-72m8-9m7m-h278
- PYSEC-2026-3478

## Timeline

- 2026-06-30: disclosed: Initial disclosure by reporter
- 2026-07-08: advisory: NVD publication
- 2026-07-22: advisory: GitHub Advisory published

## References

- [https://api.github.com/users/yaaras](https://api.github.com/users/yaaras)
- [https://github.com/yaaras](https://github.com/yaaras)
- [https://api.github.com/users/yaaras/gists%7B/gist_id%7D](https://api.github.com/users/yaaras/gists%7B/gist_id%7D)
- [https://api.github.com/users/yaaras/repos](https://api.github.com/users/yaaras/repos)
- [https://avatars.githubusercontent.com/u/35866567?v=4](https://avatars.githubusercontent.com/u/35866567?v=4)
- [https://api.github.com/users/yaaras/events%7B/privacy%7D](https://api.github.com/users/yaaras/events%7B/privacy%7D)

## Related threats

- [LiteLLM arbitrary local file read via vertex_ai_credentials](https://junglewise.ai/threats/litellm-internal-user-viewer-arbitrary-local-file-read-via-vertex-ai-649a7475)
- [LiteLLM reflected XSS in SSO debug callback endpoint](https://junglewise.ai/threats/litellm-vulnerable-to-reflected-xss-in-sso-debug-callback-38154651)
- [LiteLLM proxy authentication bypass via reused crypto context](https://junglewise.ai/threats/cve-2026-114612-litellm-is-a-proxy-server-ai-gateway-to-call-llm-apis-in-openai)
- [BerriAI LiteLLM improper authorization in secret resolution](https://junglewise.ai/threats/cve-2026-108575-a-vulnerability-has-been-found-in-berriai-litellm-up-to-1-94-0)
- [BerriAI LiteLLM authorization bypass in spend tracking](https://junglewise.ai/threats/cve-2026-108574-a-flaw-has-been-found-in-berriai-litellm-up-to-1-95-0-affected)
