Summary
pgjdbc may fail to enforce TLS when connection settings are supplied through certain properties, service definitions, or URL-setting sequences. If a connection falls back to plaintext or otherwise lacks the requested TLS protection, an attacker on the network path may read or modify database traffic.
Affected context
The issue affects pgjdbc versions 9.4.1208 through 42.7.14 when connection configuration reaches one of the affected parsing or precedence paths. Examples include using an ssl value without an explicit sslmode, supplying a service through Properties whose pg_service.conf entry specifies sslmode, or setting connection options before calling BaseDataSource.setUrl(). The resulting connection may not apply the intended TLS settings.
Exploit preconditions
- Attack surface: Network traffic between a pgjdbc client and a PostgreSQL server
- Required access: An attacker must be positioned to observe or interfere with that traffic; access to the application's configuration may also be needed to establish an affected settings path
- Trigger point: The client creates a connection using one of the affected combinations of properties, service settings, or URL and data-source options
- Why exploitation is possible: TLS settings can be ignored, weakened, or retained unexpectedly, allowing a connection to proceed without the protection the configuration intended
Why this happens
The driver does not consistently resolve and enforce TLS-related settings across connection configuration sources. In affected cases, an ssl value can map to a mode that permits fallback, a service setting can be lost, or previously set data-source options can persist when the URL is changed. This is primarily associated with CWE-319: Cleartext Transmission of Sensitive Information when traffic is sent without TLS; the failure to apply expected security settings is also related to CWE-295: Improper Certificate Validation.
Potential impact
- An attacker on the network path may read database credentials or query data if the connection uses plaintext.
- Database requests or responses could be modified in transit.
- Sensitive information could be exposed, potentially leading to unauthorized access or data integrity issues.
General mitigation guidance
Defensive patterns include making TLS mandatory by default and using explicit, unambiguous connection settings rather than relying on aliases or fallback behavior. Use certificate and hostname verification where appropriate, and reject configurations that do not satisfy the required transport security policy. Ensure settings from URLs, properties, service definitions, and data-source APIs are merged with documented, consistent precedence; reduce reliance on externally mutable configuration and limit database account privileges.
How teams detect issues like this
- Review connection setup code for implicit TLS defaults, fallback modes, and conflicting settings from URLs, properties, service files, or data-source methods.
- Use static analysis and code review checks to flag connection configurations that do not explicitly meet the application's TLS policy.
- Test representative configuration combinations and verify the negotiated transport and certificate checks at runtime.
- Enforce policies that reject database connections unless required TLS protections are active; monitor connection metadata for unexpected plaintext sessions.

