diff --git a/src/Server/TCPHandler.cpp b/src/Server/TCPHandler.cpp index 915db9c5c7d..587e446d6dd 100644 --- a/src/Server/TCPHandler.cpp +++ b/src/Server/TCPHandler.cpp @@ -690,6 +690,13 @@ void TCPHandler::runImpl() LOG_WARNING(log, "Client has gone away."); } + /// Interserver authentication is done only after we read the query. + /// This fact can be abused by producing exception before or while we read the query. + /// To aovid any potential exploits, we simply close connection on any exceptions + /// that happen before the first query is authenticated with the cluster secret. + if (is_interserver_mode && exception && !is_interserver_authenticated) + exception->rethrow(); + try { /// A query packet is always followed by one or more data packets. @@ -1797,6 +1804,8 @@ void TCPHandler::receiveQuery() /// address. session->authenticate(AlwaysAllowCredentials{client_info.initial_user}, client_info.initial_address); } + + is_interserver_authenticated = true; #else auto exception = Exception(ErrorCodes::AUTHENTICATION_FAILED, "Inter-server secret support is disabled, because ClickHouse was built without SSL library"); diff --git a/src/Server/TCPHandler.h b/src/Server/TCPHandler.h index 9fd243baa6c..45c10b1c27d 100644 --- a/src/Server/TCPHandler.h +++ b/src/Server/TCPHandler.h @@ -200,6 +200,7 @@ private: bool is_ssh_based_auth = false; /// For inter-server secret (remote_server.*.secret) bool is_interserver_mode = false; + bool is_interserver_authenticated = false; /// For DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET String salt; /// For DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET_V2