litellm(pip) — vulnerable:>= 1.81.16, < 1.83.7→ patched in1.83.7
CWE-89 — Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Packages
Vulnerability Analysis
The vulnerability is a SQL injection in the LiteLLM proxy's API key verification logic. The advisory states that a database query mixed a caller-supplied key value directly into the query text. By analyzing the commits between the vulnerable version and the patched version, I identified commit 4dc416ee749122ca91e3bca095217478663419e7 as the security patch. This commit modifies the get_data function in litellm/proxy/utils.py. The diff clearly shows the change from an unsafe f-string-based query construction (WHERE v.token = '{token}') to a parameterized query (WHERE v.token = $1). The hashed_token is then passed as a separate argument, preventing the SQL injection. The primary vulnerable function is ProxyUtils.get_data, as it is responsible for creating the malicious query. The helper function _query_first_with_cached_plan_fallback was also updated to support passing these parameters, making it a relevant part of the fix.
Identified Vulnerable Functions
ProxyUtils.get_dataThe function get_data within the ProxyUtils class constructs a raw SQL query to validate an API token. The original code used an f-string to embed the hashed_token directly into the query string, which is a classic SQL injection vulnerability. An attacker could craft a malicious token that, when inserted into the query, could alter the query's logic to bypass authentication or exfiltrate data from the database.
ProxyUtils._query_first_with_cached_plan_fallbackThis function was modified to accept and pass query parameters (*args) to the underlying database driver. While not the source of the vulnerability itself, it was a necessary change to allow the get_data function to use parameterized queries, which is the fix for the SQL injection. This function is part of the vulnerable execution path.