Summary
LiteLLM's API key verification logic used a dynamically constructed SQL query that directly embedded the caller's Authorization header value into the query text instead of binding it as a parameter.
An unauthenticated attacker can send a crafted Authorization header to any LLM API route and, via an error-handling path, inject arbitrary SQL, potentially reading or modifying the proxy's database and gaining unauthorized access to managed credentials.
Affected context
The vulnerability affects LiteLLM deployments using versions 1.81.16 up to (but not including) 1.83.7 where:
- The proxy is configured with a backing database for API key management.
- API key checks are performed against this database as part of request handling.
- Error-handling or fallback logic still reaches the vulnerable query even when authentication fails.
In this context, any exposed LLM API route (e.g., POST /chat/completions) that accepts an Authorization header can become an injection point into the proxy's database.
Exploit preconditions
- Attack surface: Public or internal LiteLLM HTTP endpoints that:
- Accept an Authorization header.
- Trigger API key verification, including error-handling paths.
- Required access: Network-level ability to send requests to the LiteLLM proxy (no prior authentication required).
- Trigger point: The database query executed during proxy API key validation, reached via normal or error-handling code paths.
- Why exploitation is possible: The query building logic interpolates the user-supplied API key directly into the SQL string instead of using parameterized queries, allowing crafted input to alter the intended SQL command.
Why this happens
This issue stems from constructing SQL statements by concatenating untrusted input from the Authorization header directly into the query text.
Rather than using parameterized queries or prepared statements, the code dynamically builds the WHERE clause (or similar filter) with the caller's API key embedded verbatim.
This pattern maps directly to CWE-89: SQL Injection, where data and code are not cleanly separated, enabling an attacker to inject their own SQL fragments that the database executes with the application's privileges.
Potential impact
- Read arbitrary or sensitive data from the LiteLLM proxy database, including stored API keys or credentials.
- Modify or delete database records, such as API key entries, access control data, or configuration values.
- Create or enable unauthorized accounts or API keys, leading to sustained unauthorized access.
- Tamper with logging or audit information stored in the database to obscure malicious activity.
- Potentially pivot to other systems that rely on credentials or configuration secrets stored by the proxy.
General mitigation guidance
Effective mitigation centers on strictly separating user input from SQL control logic and narrowing what data queries can touch:
- Use parameterized queries or prepared statements for all database interactions involving external input, including error-handling paths.
- Introduce a data access layer that encapsulates query construction and enforces safe patterns by default.
- Apply least-privilege to the database account used by the proxy so it can only perform the minimal required operations on the minimal set of tables.
- Constrain API key values to an expected format (length, character set) and reject values that deviate from this profile before they reach the database layer.
- Implement centralized error handling that does not trigger additional dynamic queries based on attacker-controlled data.
- Regularly review and refactor legacy query-building code to replace string concatenation with secure abstractions.
How teams detect issues like this
Organizations can detect and monitor for this class of issue using complementary approaches:
- Static analysis: Configure SAST tools or linters to flag string-concatenated SQL queries and direct interpolation of request fields (e.g., Authorization headers) into query text.
- Code review: During reviews, treat any query construction that is not parameterized as a high-risk code smell, especially in authentication, authorization, and error-handling paths.
- Database monitoring: Enable query logging and alert on anomalous patterns such as always-true conditions (e.g., '1=1'), unexpected UNIONs, or stacked statements if the DB permits them.
- Runtime protections: Employ application-layer firewalls or API gateways with rules tuned to common SQL injection patterns to provide an additional detection layer.
- Policy enforcement: Enforce development policies that prohibit raw SQL concatenation with user input and require the use of vetted data access utilities or ORM layers.

