Skip to content

fix(pg): refuse ReadyForQuery before authentication completes - #3844

Open
AadiBolics wants to merge 5 commits into
brianc:masterfrom
AadiBolics:fix/3841-ready-for-query-before-auth
Open

AadiBolics wants to merge 5 commits into
brianc:masterfrom
AadiBolics:fix/3841-ready-for-query-before-auth

Conversation

@AadiBolics

Copy link
Copy Markdown

Closes #3841.

During connect, Client accepted the first ReadyForQuery as a finished connection regardless of what came before it. A server that answers the startup message with ReadyForQuery alone, with no authentication request, connects successfully and the configured password is never requested. libpq refuses the same server.

The fix tracks authenticationOk and accepts the first ReadyForQuery only after authentication has completed. A ReadyForQuery arriving while connecting without a prior AuthenticationOk now fails connect() with "expected authentication request from server, but received Z" and closes the connection. The protocol requires every authentication exchange, including trust auth, to end with AuthenticationOk, so conforming servers are unaffected.

Tests: a new ready-for-query-before-auth-tests.js uses a scripted TCP server to assert connect() fails when ReadyForQuery arrives with no authentication, and still succeeds after AuthenticationOk. The unit test helper and the two tests with hand-rolled connections now emit authenticationOk, mirroring the real handshake. The full test/unit suite passes locally.

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.

Client treats a ReadyForQuery before any authentication message as a connected session

1 participant