You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
postgres: NewPool checks the server certificate against "localhost" and keeps localhost fallbacks #492
pgxpool.ParseConfig builds the TLS settings and the fallback list for the host it parses, localhost. Reassigning ConnConfig.Host afterwards does not update them:
sslMode: verify-full never connects to a real server. pgx sets TLSConfig.ServerName to localhost, so the server certificate is checked against localhost instead of cfg.Host, and the hostname check fails.
sslMode: prefer and allow keep a fallback to localhost:5432. If the first attempt fails, pgx tries localhost:5432 instead of cfg.Host; with prefer that attempt is unencrypted.
require (the default) and verify-ca are not affected: neither checks the host name and neither has a fallback.
Fix
In buildPoolConfig, after assigning Host and Port:
when pc.ConnConfig.TLSConfig != nil, set pc.ConnConfig.TLSConfig.ServerName = cfg.Host;
point every entry of pc.ConnConfig.Fallbacks at cfg.Host / cfg.Port (setting ServerName on each fallback's TLSConfig too), or clear Fallbacks for the modes that have none.
Test
A unit test over each sslMode can assert, without a server, that ServerName equals cfg.Host and that no fallback targets localhost. An integration test against a Postgres serving a certificate for a non-localhost name would cover verify-full end to end.
Activity