diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index dd5edcfe7..74e73cc0b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -61,7 +61,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(Handshake handshake) { - InitialInboundConnection ic = new InitialInboundConnection(connection, handshake); + InitialInboundConnection ic = new InitialInboundConnection(connection, cleanVhost(handshake.getServerAddress()), handshake); switch (handshake.getNextStatus()) { case StateRegistry.STATUS_ID: connection.setState(StateRegistry.STATUS); @@ -109,6 +109,11 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } } + private String cleanVhost(String hostname) { + int zeroIdx = hostname.indexOf('\0'); + return zeroIdx == -1 ? hostname : hostname.substring(0, zeroIdx); + } + @Override public void handleGeneric(MinecraftPacket packet) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index 1518eb5d5..411a3faa9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -9,10 +9,12 @@ import java.util.Optional; class InitialInboundConnection implements InboundConnection { private final MinecraftConnection connection; + private final String cleanedAddress; private final Handshake handshake; - InitialInboundConnection(MinecraftConnection connection, Handshake handshake) { + InitialInboundConnection(MinecraftConnection connection, String cleanedAddress, Handshake handshake) { this.connection = connection; + this.cleanedAddress = cleanedAddress; this.handshake = handshake; } @@ -23,7 +25,7 @@ class InitialInboundConnection implements InboundConnection { @Override public Optional getVirtualHost() { - return Optional.of(InetSocketAddress.createUnresolved(handshake.getServerAddress(), handshake.getPort())); + return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort())); } @Override