From 967b36259028deb1ec91172e65c8df24b7995f3b Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Fri, 3 Nov 2023 17:33:05 -0400 Subject: [PATCH] Validate protocol version on handshake --- chia/server/ws_connection.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/chia/server/ws_connection.py b/chia/server/ws_connection.py index c8cda6d30060..e92d5012ada2 100644 --- a/chia/server/ws_connection.py +++ b/chia/server/ws_connection.py @@ -222,11 +222,15 @@ async def perform_handshake( if inbound_handshake.network_id != network_id: raise ProtocolError(Err.INCOMPATIBLE_NETWORK_ID) - inbound_node_type = NodeType(inbound_handshake.node_type) + if inbound_handshake.protocol_version != protocol_version: + self.log.warning( + f"protocol version mismatch: incoming={inbound_handshake.protocol_version} our={protocol_version}" + ) + self.version = inbound_handshake.software_version self.protocol_version = Version(inbound_handshake.protocol_version) self.peer_server_port = inbound_handshake.server_port - self.connection_type = inbound_node_type + self.connection_type = NodeType(inbound_handshake.node_type) # "1" means capability is enabled self.peer_capabilities = known_active_capabilities(inbound_handshake.capabilities) else: @@ -251,12 +255,16 @@ async def perform_handshake( if inbound_handshake.network_id != network_id: raise ProtocolError(Err.INCOMPATIBLE_NETWORK_ID) - inbound_node_type = NodeType(inbound_handshake.node_type) + if inbound_handshake.protocol_version != protocol_version: + self.log.warning( + f"protocol version mismatch: incoming={inbound_handshake.protocol_version} our={protocol_version}" + ) + await self._send_message(outbound_handshake) self.version = inbound_handshake.software_version self.protocol_version = Version(inbound_handshake.protocol_version) self.peer_server_port = inbound_handshake.server_port - self.connection_type = inbound_node_type + self.connection_type = NodeType(inbound_handshake.node_type) # "1" means capability is enabled self.peer_capabilities = known_active_capabilities(inbound_handshake.capabilities)