From 8fb1ea9e2d0ade4dbec680d86304094171ab3cb2 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 27 Apr 2021 16:38:35 -0700 Subject: [PATCH] Updated Upstream (Spigot) (#5550) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Spigot Changes: 4225eac0 SPIGOT-6423: Improve IP forwarding --- ...name.patch => Add-bypass-host-check.patch} | 37 +++---------------- ...ent-to-allow-plugins-to-handle-clien.patch | 2 +- work/Spigot | 2 +- 3 files changed, 8 insertions(+), 33 deletions(-) rename Spigot-Server-Patches/{Validate-bungee-forwarded-hostname.patch => Add-bypass-host-check.patch} (56%) diff --git a/Spigot-Server-Patches/Validate-bungee-forwarded-hostname.patch b/Spigot-Server-Patches/Add-bypass-host-check.patch similarity index 56% rename from Spigot-Server-Patches/Validate-bungee-forwarded-hostname.patch rename to Spigot-Server-Patches/Add-bypass-host-check.patch index 515786dd4a..0c1e46628b 100644 --- a/Spigot-Server-Patches/Validate-bungee-forwarded-hostname.patch +++ b/Spigot-Server-Patches/Add-bypass-host-check.patch @@ -1,7 +1,9 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 18 Apr 2021 21:27:01 +0100 -Subject: [PATCH] Validate bungee forwarded hostname +Subject: [PATCH] Add bypass host check + +Paper.bypassHostCheck Seriously, fix your firewalls. -.- @@ -9,15 +11,6 @@ diff --git a/src/main/java/net/minecraft/server/network/HandshakeListener.java b index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/network/HandshakeListener.java +++ b/src/main/java/net/minecraft/server/network/HandshakeListener.java -@@ -0,0 +0,0 @@ - package net.minecraft.server.network; - -+import com.google.common.net.InetAddresses; -+import com.google.common.net.InternetDomainName; -+ - import net.minecraft.SharedConstants; - import net.minecraft.network.EnumProtocol; - import net.minecraft.network.NetworkManager; @@ -0,0 +0,0 @@ public class HandshakeListener implements PacketHandshakingInListener { private static final IChatBaseComponent a = new ChatComponentText("Ignoring status request"); private final MinecraftServer b; @@ -27,29 +20,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public HandshakeListener(MinecraftServer minecraftserver, NetworkManager networkmanager) { this.b = minecraftserver; @@ -0,0 +0,0 @@ public class HandshakeListener implements PacketHandshakingInListener { + // Spigot Start //if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above! String[] split = packethandshakinginsetprotocol.hostname.split("\00"); - if ( split.length == 3 || split.length == 4 ) { -+ // Paper start -+ if (!BYPASS_HOSTCHECK && !validate(split[1])) { -+ final ChatMessage message = new ChatMessage("Invalid hostname"); -+ this.getNetworkManager().sendPacket(new PacketLoginOutDisconnect(message)); -+ this.getNetworkManager().close(message); -+ return; -+ } -+ // Paper end +- if ( ( split.length == 3 || split.length == 4 ) && ( HOST_PATTERN.matcher( split[1] ).matches() ) ) { ++ if ( ( split.length == 3 || split.length == 4 ) && ( BYPASS_HOSTCHECK || HOST_PATTERN.matcher( split[1] ).matches() ) ) { // Paper packethandshakinginsetprotocol.hostname = split[0]; c.socketAddress = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) c.getSocketAddress()).getPort()); c.spoofedUUID = com.mojang.util.UUIDTypeAdapter.fromString( split[2] ); -@@ -0,0 +0,0 @@ public class HandshakeListener implements PacketHandshakingInListener { - public NetworkManager a() { - return this.c; - } -+ -+ // Paper start - https://stackoverflow.com/questions/9954140/check-if-a-string-is-a-hostname-or-an-ip-address-in-java -+ public static boolean validate(final String hostname) { -+ //noinspection UnstableApiUsage -+ return InetAddresses.isUriInetAddress(hostname); -+ } -+ // Paper end - } diff --git a/Spigot-Server-Patches/Add-handshake-event-to-allow-plugins-to-handle-clien.patch b/Spigot-Server-Patches/Add-handshake-event-to-allow-plugins-to-handle-clien.patch index 487774ff61..a512e8e811 100644 --- a/Spigot-Server-Patches/Add-handshake-event-to-allow-plugins-to-handle-clien.patch +++ b/Spigot-Server-Patches/Add-handshake-event-to-allow-plugins-to-handle-clien.patch @@ -52,5 +52,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - if (org.spigotmc.SpigotConfig.bungee) { + //if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above! String[] split = packethandshakinginsetprotocol.hostname.split("\00"); - if ( split.length == 3 || split.length == 4 ) { + if ( ( split.length == 3 || split.length == 4 ) && ( HOST_PATTERN.matcher( split[1] ).matches() ) ) { packethandshakinginsetprotocol.hostname = split[0]; diff --git a/work/Spigot b/work/Spigot index a25e8ed26c..4225eac084 160000 --- a/work/Spigot +++ b/work/Spigot @@ -1 +1 @@ -Subproject commit a25e8ed26cbca903b4d6ee3823d1b9f4f5d06cc3 +Subproject commit 4225eac084af31c8b9dca9eed3f7d146f3bc3625