fix(proxy): _strip_prisma_query_params drops host, breaking every Unix-socket Postgres deployment

_strip_prisma_query_params filters DATABASE_URL through an allowlist of
libpq parameters before handing it to psycopg. host was not in that
allowlist, so it got stripped. host is a libpq parameter, and passing
an absolute path in it is the documented way to select a Unix socket.
The function's own docstring says it exists so psycopg can parse the
URL, but psycopg parses host correctly, the allowlist is what broke it.

A Unix socket is how managed Postgres is reached on Cloud Run, App
Engine, and Cloud Functions. Stripping host from a Cloud SQL URL
(postgresql://user:pass@localhost/db?host=/cloudsql/project:region:instance)
leaves the netloc reading @localhost, so psycopg connects to
localhost:5432 where nothing is listening. The Prisma CLI gets the URL
untouched and works fine, so migrations apply and the breakage stays
invisible until something else that goes through this stripped URL
needs the socket.

Added host, hostaddr, and port to libpq_params, they are the same
class of parameter and have the same problem.

fixes #43578
This commit is contained in:
Ishan Katoch 2026-09-29 15:13:04 +05:30
parent 85dc7cb62e
commit 8429e0b874
2 changed files with 21 additions and 0 deletions

View file

@ -656,6 +656,9 @@ class ProxyExtrasDBManager:
if not parsed.query:
return url
libpq_params = {
"host",
"hostaddr",
"port",
"sslmode",
"sslcert",
"sslkey",

View file

@ -71,6 +71,24 @@ def test_strip_prisma_query_params_passthrough_no_query():
assert ProxyExtrasDBManager._strip_prisma_query_params(url) == url
def test_strip_prisma_query_params_keeps_unix_socket_host():
"""A Cloud SQL-style Unix socket path in `host` must survive stripping,
it is the documented way to select a Unix socket, not a Prisma-only param."""
url = "postgresql://user:pass@localhost/litellm?host=/cloudsql/project:region:instance"
stripped = ProxyExtrasDBManager._strip_prisma_query_params(url)
assert "host=" in stripped
assert "%2Fcloudsql%2Fproject%3Aregion%3Ainstance" in stripped
def test_strip_prisma_query_params_keeps_hostaddr_and_port():
"""hostaddr and port are the same class of libpq param as host."""
url = "postgresql://u:p@h:5432/db?hostaddr=10.0.0.5&port=6543&connection_limit=100"
stripped = ProxyExtrasDBManager._strip_prisma_query_params(url)
assert "hostaddr=10.0.0.5" in stripped
assert "port=6543" in stripped
assert "connection_limit" not in stripped
def test_migration_timestamp_extracts_leading_digits():
assert _migration_timestamp("20260101000000_add_foo") == 20260101000000
assert _migration_timestamp("20250326162113_baseline") == 20250326162113