LiteLLM security finding · plain-English explainer

A cheap key that buys the expensive model

An AI gateway was supposed to lock each API key to a set of models. It turns out one guard checks the wrong place, so a key limited to a cheap model can quietly reach an expensive one. Here is what broke, how serious it is, and how it connects to a second fix that is already open.

Type: access-control / cost bypass Reproduced 55/55 BerriAI/litellm

First, the cast of characters

If you have never run an AI gateway, here is the whole world in one picture. A company puts a gateway (LiteLLM) in front of several AI models. Each user gets an API key, and the operator can scope that key to only certain models, for example "this key may only use the cheap model."

flowchart LR
    U["App / user
holds an API key"] --> G{{"Gateway (LiteLLM)
checks the key's allowed models"}} G -->|allowed| C["Cheap model
$0.0002 / call"] G -.->|blocked| P["Premium model
$0.20 / call"] classDef ok fill:#edf6f1,stroke:#1f6f54,color:#16130f; classDef no fill:#f3efe6,stroke:#b8b0a0,color:#8a8275,stroke-dasharray:4 3; classDef gw fill:#eef3fb,stroke:#2b5fa8,color:#16130f; class C ok; class P no; class G gw;
The promise: a key scoped to the cheap model should never reach the premium model.

That "allowed models" list is the whole point. Operators rely on it to control cost and access, for example giving a customer a key that can only touch one inexpensive model.

The bug, in one sentence

Two parts of the gateway read the request differently. The security guard decides which model to allow by reading the model named in the request body. The router decides which model to actually run by reading the model named in the URL. If you put the allowed model in the body and the forbidden model in the URL, the guard says yes and the router runs the forbidden one.

The "two doors" picture

Imagine a nightclub. The bouncer checks the name on your ticket, but the DJ plays whatever name is on your wristband. Put an allowed name on the ticket and a VIP name on the wristband, and you walk in cheap but get the VIP treatment.

flowchart TB
    R["Your request"] --> B["Body says:
cheap-model (allowed)"] R --> Ur["URL says:
premium-model (forbidden)"] B --> Guard{{"Guard reads the BODY
sees cheap-model -> allow"}} Ur --> Router{{"Router reads the URL
sees premium-model -> run it"}} Guard --> OK["Request passes the check"] Router --> Served["Premium model is served
and billed"] OK --> Served classDef bad fill:#fbeeec,stroke:#c0392b,color:#16130f; classDef g fill:#eef3fb,stroke:#2b5fa8,color:#16130f; class Served,Ur bad; class Guard,Router g;
The guard and the router look at different fields, so they disagree about which model you asked for.
Why it normally works. If you only name the model in the body, both the guard and the router read the same field and agree. And if you only name the forbidden model in the URL (no body model), the guard falls back to reading the URL and correctly blocks you with a 403. The bypass needs both: an allowed model in the body to pass the guard, and a forbidden model in the URL for the router to run.

Which doors are unlocked

This "URL vs body" split only bites on routes where the handler takes the model from the URL. The gateway already fixed the main chat route the same way (an open community fix, PR #41852). The routes still open are the ones that fix does not list:

On all of these, a key scoped to the cheap model is served the premium model. The /v1/messages route, by contrast, correctly ignores the URL model, so it is not affected.

How serious is it?

not a data leak
cost + policy bypass

Honest severity: medium. Here is the balanced view, both the worrying parts and the limits.

What's bad
  • The key's model limit, a real security boundary, is not enforced on these routes.
  • The operator pays for the expensive model. We measured a $1 budget drained by five premium calls that the key should never have been able to make.
  • No error, no warning. The caller gets a clean 200.
What limits it
  • Not a data breach: no other customer's data is exposed. It is one key reaching extra models.
  • You must already hold a valid, authenticated key.
  • You must hand-craft the request. Normal Google SDKs don't send a body model, so this is a key holder deliberately bypassing their own scope.
55/55
reproductions across the test matrix
$0.20
per premium call, billed to a cheap-scoped key
6th
call hits budget_exceeded after 5 drain a $1 budget

The two pull requests, and where they overlap

This gateway is being hardened route-by-route. Two findings tackle the same underlying bug on different routes. They touch one route in common.

PR #76 · finding 098

The image routes

Covers /v1/images/generations, /v1/images/edits, the ?model= form and the /openai/deployments/{model}/images/... form. Proven with a real database-backed key and two separate upstreams, so the served model is shown by which upstream actually got the call. Open.

PR #77 · finding 111

The Gemini routes

Covers :generateContent and :streamGenerateContent (plus the one shared image route). Adds the billing and budget-drain proof, and a control that applies the upstream fix and shows these routes still bypass. Open.

flowchart TB
    RC["Same root cause
guard reads body model · router reads URL model"] RC --> P76["PR #76 / 098
image routes"] RC --> P77["PR #77 / 111
Gemini routes"] P76 --> A["/v1/images/generations ?model="] P76 --> Bn["/v1/images/edits"] P76 --> S["/openai/deployments/{model}/images/generations"] P77 --> S P77 --> C[":generateContent"] P77 --> D[":streamGenerateContent"] class S overlap classDef overlap fill:#fbe7a6,stroke:#b8791a,color:#16130f,stroke-width:2px; classDef p fill:#eef3fb,stroke:#2b5fa8,color:#16130f; class P76,P77 p;
The yellow box is the only route both PRs cover. Everything else is complementary.
The overlap in one line. Both PRs are the same bug. PR #76 owns the image routes end to end. PR #77's unique contribution is the Gemini generateContent / streamGenerateContent routes plus the money proof. They share exactly one route, the image-deployment path.

And the third, upstream PR

There is also an open fix in the gateway project itself, BerriAI/litellm #41852. It closes this same bug, but only for the chat / completions / embeddings routes. Its route list does not include the Gemini or image routes, which is exactly why those findings are still needed: applying #41852 and re-testing shows the Gemini and image routes still bypass.

flowchart LR
    Fix["Upstream fix
PR #41852 (open)"] -->|closes| Chat["chat / completions / embeddings ✓"] Fix -.->|does NOT touch| Gem["generateContent ✗"] Fix -.->|does NOT touch| Img["images routes ✗"] classDef ok fill:#edf6f1,stroke:#1f6f54,color:#16130f; classDef no fill:#fbeeec,stroke:#c0392b,color:#16130f; classDef f fill:#eef3fb,stroke:#2b5fa8,color:#16130f; class Chat ok; class Gem,Img no; class Fix f;
The official fix stops at the chat routes. The Gemini and image routes are the gap these two findings fill.

The fix, in one sentence

Make the guard also check the model named in the URL on the Gemini and image routes, exactly the way the open chat-route fix already does, so the model that actually runs is the one the key was checked against.