Case Studies

LiteLLM Supply-Chain Breach: How Agent Secrets Leak

SafeDep reports that LiteLLM 1.107.0 was compromised in a PyPI supply-chain attack. The incident exposes how a poisoned package can steal credentials, leverage Agent privileges, and turn a single dependency update into a broader runtime security failure.

Font size

LiteLLM 1.107.0 was found to contain a credential stealer and a backdoor. The exposure extends beyond a vulnerable dependency version: Agent teams must now examine their PyPI packages, environment variables, and runtime permissions.

According to SafeDep's original analysis, the malicious version installs a Credential Stealer and a Backdoor.

The core issue is clear: an Agent's security boundary is not limited to Prompt Injection. Beyond model inputs, Python dependencies, model gateways, environment variables, and tool permissions can all become attack surfaces.

How a PyPI Poisoning Reached Agent Credentials

LiteLLM is a multi-model gateway and proxy framework. It often sits between an application and model providers, routing requests, managing model configurations, and handling calls to different providers.

A typical deployment might look like this:

from litellm import completion

response = completion(
    model="anthropic/claude-sonnet-4-5",
    messages=[{"role": "user", "content": "Summarize this ticket"}],
    api_key=os.environ["ANTHROPIC_API_KEY"],
)

The process running LiteLLM usually has access to more than one provider's credentials.

It may hold:

  • API keys for model providers such as Anthropic and OpenAI;
  • Access credentials for AWS, Azure, or Google Cloud;
  • Credentials for databases, object storage, and internal services;
  • Internal API tokens required for Agent tool calls;
  • Keys for logging, billing, monitoring, and tracing systems.

The danger of a package update goes beyond “installing a malicious version.” Malicious code running inside the gateway process can exploit the permissions already available to that process.

The Specific Risks in LiteLLM 1.107.0

SafeDep reports that the PyPI package for LiteLLM 1.107.0 was compromised in a supply-chain attack. The report title and summary explicitly state that the version was confirmed to install a Credential Stealer and Backdoor.

Two distinct issues need to be separated:

  1. Supply-chain compromise: an attacker entered the legitimate package publishing or distribution pipeline;
  2. Malicious functionality: after installation, the package contained credential-stealing and backdoor capabilities.

This differs from ordinary typo-squatting.

Typo-squatting typically involves an imitation package with a similar or misspelled name that tricks users into installing it. The attacker relies on a user making a typing error.

This incident is closer to “the original package was replaced” or “the publishing process was compromised.” The dependency name was correct, and the project genuinely used LiteLLM, but the package itself changed after a specific version update.

Engineering teams need to revise their default security assumptions:

Correct package name ≠ safe version
Lockfile present ≠ every package is trustworthy
CI installation succeeds ≠ production ran no malicious logic

Pay particular attention to postinstall scripts, build scripts, and dynamic installation logic. Malicious code does not necessarily run only when application code calls it. It may execute during installation, process startup, or module import.

Original security analysis: https://safedep.io/litellm-pypi-compromise-credential-stealer-backdoor/

Installation Is Not the Main Danger—Credential Access Is

Credential Stealer and Backdoor represent two different levels of risk.

The credential stealer addresses what an attacker can obtain:

  • Environment variables;
  • Cloud service configuration;
  • Local credential files;
  • Tokens held in a running process;
  • API keys used by proxy services.

The backdoor addresses how the attacker can return later:

  • Maintaining a persistent entry point into the environment;
  • Waiting for follow-up commands;
  • Restoring execution under specific conditions;
  • Preventing a short-term fix from fully removing the risk.

Combined, the two capabilities can turn a one-time data theft into a persistent security problem.

For a conventional application, leaking a chat API key may mean unauthorized charges and reduced request capacity. The impact is often greater for an AI Agent.

An Agent does more than generate text. If it can invoke tools, it may:

  • Read a source-code repository;
  • Modify files and commit changes;
  • Query internal databases;
  • Call ticketing, CRM, or email systems;
  • Deploy services;
  • Initiate payments or cloud resource operations.

Once a model gateway or Agent runtime holds high-privilege credentials, Prompt Injection becomes only one possible follow-on attack. An attacker may not need to trick the model into opening a link. Malicious code can read credentials directly or impersonate subsequent calls.

The critical privilege chain is:

Malicious PyPI package
    ↓
Agent runtime / LiteLLM process
    ↓
Environment variables, config files, cloud credentials
    ↓
Internal APIs, source repositories, production systems

Three Containment Steps for AI Engineering Teams

1. Pin Versions and Verify Hashes

Do not specify only a version range:

[project]
dependencies = [
  "litellm>=1.100.0",
]

This allows each build to resolve a potentially different version. That is not sufficient for production Agents.

Pin an exact version and record the complete dependency set in a lockfile. Installation can also verify hashes:

python -m pip install --require-hashes -r requirements.txt

CI should preserve and review:

  • Exact versions in requirements.txt;
  • Lockfiles generated by poetry.lock, uv.lock, or pip-tools;
  • Package file hashes;
  • Dependency trees from pip list, pipdeptree, or uv pip tree;
  • Scripts actually executed during the build and installation stages.

For any version exposed during the incident window, do not simply upgrade and continue using it. First determine whether the malicious version executed, then identify which credentials need to be rotated.

2. Rotate Every Credential That Appeared in the Environment

If LiteLLM 1.107.0 entered a developer machine, CI runner, container image, or production environment, assume by default that related credentials may have been exposed.

Review at least:

  • Model-provider API keys;
  • Cloud-platform access keys;
  • Database passwords and connection strings;
  • Tokens for code platforms such as GitHub, GitLab, and GitHub Actions;
  • Tokens for Slack, email, monitoring, and logging services;
  • Credentials for internal services callable by the Agent.

Rotation means more than generating a new key. Run old and new keys in parallel during the switchover, verify that the old key is invalid, and review logs for anomalous calls.

Also review permissions. A key intended only to call Claude should not simultaneously grant access to source repositories or production deployment.

3. Isolate Deployment Credentials

A model gateway should run in a separate, least-privilege environment whenever possible.

One way to structure the environment is:

Agent API service
  └─ Holds only a short-lived Agent token

LiteLLM gateway
  └─ Holds only the required model-provider keys

Deployment and cloud control plane
  └─ Does not enter the Agent container

Practical measures include:

  • Isolating runtime environments with containers or virtual machines;
  • Preventing the Agent runtime from reading cloud control-plane credentials;
  • Using short-lived tokens with automatic expiration;
  • Applying allowlists to tool calls;
  • Restricting the gateway's outbound network access;
  • Using a separate CI/CD identity for production deployments;
  • Blocking default access to sensitive directories such as ~/.aws, ~/.ssh, and ~/.config;
  • Rechecking permissions immediately before processing external input.

Teams can use this checklist from CI through production:

[ ] Was LiteLLM 1.107.0 installed?
[ ] Were any dependencies resolved without version pinning?
[ ] Did the build include postinstall or dynamic download behavior?
[ ] Were build images and caches inspected?
[ ] Were model, cloud, and internal API credentials rotated?
[ ] Does the Agent runtime hold unnecessary production permissions?
[ ] Were anomalous token usage and outbound connections reviewed?

Teams using LangGraph, MCP, or a custom tool layer should include every layer in the investigation. The gateway is only one part of the dependency chain.

Engineering Implications

The significance of this incident does not depend on whether LiteLLM remains permanently compromised. It shows that the Agent security boundary now extends beyond model responses into the runtime. A Python package update can simultaneously expose model keys, cloud credentials, and internal API permissions.

This differs from Prompt Injection. Prompt Injection usually begins with model input and requires the model to be manipulated. A supply-chain attack can occur directly at the code and permission layers without first persuading the model.

Agent teams are likely to treat least privilege as a more foundational control than Prompt Injection. Models and tools still require review, but if one gateway process holds dozens of long-lived credentials, any dependency compromise gains a much larger blast radius.

Several questions remain unresolved. The version number alone cannot establish which credentials the malicious code collected, under what conditions it gathered them, whether the Backdoor communicated with an external host, or whether the environment was compromised further. Teams should review installation logs, build caches, network connections, and credential-use records rather than assuming the risk ends with an upgrade.

Sources

Source: https://safedep.io/litellm-pypi-compromise-credential-stealer-backdoor/