Skip to content

Commit

Permalink
Properly sanitize handshake server address
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed May 22, 2024
1 parent 416fd28 commit 84d1fc2
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public HandshakeSessionHandlerHook(FastMOTD plugin, MinecraftConnection connecti
this.original = original;
}

private static String cleanHost(String hostname) {
String cleaned = hostname;
int zeroIdx = cleaned.indexOf(0);
if (zeroIdx > -1) {
cleaned = hostname.substring(0, zeroIdx);
}

if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') {
cleaned = cleaned.substring(0, cleaned.length() - 1);
}

return cleaned;
}

@Override
public boolean handle(LegacyPingPacket packet) {
this.connection.close();
Expand Down Expand Up @@ -81,7 +95,7 @@ public boolean handle(HandshakePacket handshake) {
}

this.protocolVersion = handshake.getProtocolVersion();
this.serverAddress = handshake.getServerAddress() + ":" + handshake.getPort();
this.serverAddress = cleanHost(handshake.getServerAddress()) + ":" + handshake.getPort();
this.channel.pipeline().remove(Connections.FRAME_ENCODER);
this.channel.pipeline().get(MinecraftDecoder.class).setState(StateRegistry.STATUS);

Expand Down

0 comments on commit 84d1fc2

Please sign in to comment.