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 exists in the get_data function within litellm/proxy/utils.py. The security advisory and the provided patch clearly indicate a SQL injection vulnerability. The patch replaces a formatted string in the SQL query with a parameterized query, which is the standard mitigation for SQL injection. The vulnerable line WHERE v.token = '{token}' directly uses the user-controlled token variable in the SQL query. The fix changes this to WHERE v.token = $1 and passes the token as a parameter to the database driver, preventing the injection. The vulnerability is triggered when the proxy handles an error, and an unauthenticated attacker can exploit it by sending a specially crafted Authorization header.
Identified Vulnerable Functions
get_dataThe get_data function in litellm/proxy/utils.py is vulnerable to SQL injection. The token variable, which is derived from the user-provided Authorization header, is directly formatted into the SQL query string. An attacker can craft a malicious Authorization header to inject arbitrary SQL commands, allowing them to read or modify data in the database.