From: vlsi (@vlsi) <noreply+vlsi@github.com>
To: pgjdbc/pgjdbc <noreply+pgjdbc-pgjdbc@github.com>
Subject: Re: [pgjdbc/pgjdbc] PR #4251: OAuth implementation
Date: Wed, 09 Sep 2026 15:45:36 +0000
Message-ID: <gh-pgjdbc-pgjdbc-4251-rc3970363266@github.com> (raw)
In-Reply-To: <gh-pgjdbc-pgjdbc-4251@github.com>
References: <gh-pgjdbc-pgjdbc-4251@github.com>
(on pgjdbc/src/main/java/org/postgresql/core/v3/OAuthAuthenticator.java)
This is the second blocking finding. `instanceof SSLSocket` establishes that the connection is encrypted, not that the peer is the server the user meant to reach. Under `sslmode=require` and `sslmode=prefer` pgjdbc does not validate the certificate, so a rogue endpoint with a self-signed certificate passes this check and receives the token. I harvested one that way with `oauthAllowUnencryptedConnection` left at its default `false`.
RFC 7628 asks for TLS in order to keep the bearer token from a third party, and encryption without peer authentication does not deliver that.
The second half is `sslmode=prefer`, the driver default: when authentication over TLS fails, pgjdbc reconnects without encryption and this method sends the same token again in the clear, with only a `WARNING` between the two attempts. An expired token then leaks on every reconnect attempt.
I would require `SslMode.VERIFY_CA` or higher here, and at minimum warn under `require` and `prefer`. The retry path deserves its own decision: either the token is not resent after a downgrade, or the behavior is documented and pinned by a test.