Skip to content

Surface server errors during SSL negotiation - #1348

Draft
aryansk wants to merge 1 commit into
MagicStack:masterfrom
aryansk:fix/1317-ssl-error-response
Draft

aryansk wants to merge 1 commit into
MagicStack:masterfrom
aryansk:fix/1317-ssl-error-response

Conversation

@aryansk

@aryansk aryansk commented Aug 16, 2026

Copy link
Copy Markdown

Summary

Preserve the PostgreSQL server's diagnostic when it returns an early error while asyncpg is waiting for the one-byte SSL negotiation response.

Changes

  • recognize pre-auth responses beginning with the PostgreSQL ErrorResponse marker (E)
  • decode and surface the server-provided text as an asyncpg InterfaceError
  • retain the existing S, advisory N, and generic fallback behavior
  • add a unit regression test using the reported pre-auth response shape

Test plan

python -m unittest tests.test_connect.TestTLSUpgradeProto.test_error_response_preserves_server_message

Fixes #1317

elprans added a commit that referenced this pull request Sep 20, 2026
An `ErrorResponse` to `SSLRequest` is currently reported as an SSL
refusal, while transport fallback only handles a narrow set of
authorization errors.

Follow libpq transport-selection behavior and improve the SSL exchange
diagnostic without trusting pre-TLS server text or exposing SQLSTATE
(see CVE-2024-10977).  Make it so that alternative transports in
allow/prefer retries are only tried _before_ authentication succeeds,
not after.  While here, align asyncpg with libpq and require `ssl` to be
set to a mandatory TLS mode (or explicit context) when `direct_tls` is
specified.

Fixes #1317.
Closes #1346.
Closes #1348.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TLSUpgradeProto.data_received hides PostgreSQL ErrorResponse behind generic 'rejected SSL upgrade' ConnectionError

1 participant