aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0635-Validate-usernames.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0635-Validate-usernames.patch')
-rw-r--r--patches/server/0635-Validate-usernames.patch76
1 files changed, 76 insertions, 0 deletions
diff --git a/patches/server/0635-Validate-usernames.patch b/patches/server/0635-Validate-usernames.patch
new file mode 100644
index 0000000000..e8287bc641
--- /dev/null
+++ b/patches/server/0635-Validate-usernames.patch
@@ -0,0 +1,76 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Spottedleaf <[email protected]>
+Date: Sat, 1 Jan 2022 05:19:37 -0800
+Subject: [PATCH] Validate usernames
+
+
+diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+index 1e4b288f20153ce0c91fabf164c5c8320c90ba7d..cb5dd77892283a1aaec45434fb99bb7f08ee5394 100644
+--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
++++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+@@ -90,6 +90,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
+ private final String serverId;
+ private final boolean transferred;
+ private ServerPlayer player; // CraftBukkit
++ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
+
+ public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
+ this.state = ServerLoginPacketListenerImpl.State.HELLO;
+@@ -171,7 +172,13 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
+ @Override
+ public void handleHello(ServerboundHelloPacket packet) {
+ Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
+- Validate.validState(StringUtil.isValidPlayerName(packet.name()), "Invalid characters in username", new Object[0]);
++ // Paper start - Validate usernames
++ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
++ && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation
++ && !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) {
++ Validate.validState(StringUtil.isReasonablePlayerName(packet.name()), "Invalid characters in username", new Object[0]);
++ }
++ // Paper end - Validate usernames
+ this.requestedUsername = packet.name();
+ GameProfile gameprofile = this.server.getSingleplayerProfile();
+
+diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
+index 05d2f3c26d10169f6cf43bcb6c48db5d27b5cbac..3a0e0196f5bfa554b23fff9ff1a18a189b36452e 100644
+--- a/src/main/java/net/minecraft/server/players/PlayerList.java
++++ b/src/main/java/net/minecraft/server/players/PlayerList.java
+@@ -627,7 +627,7 @@ public abstract class PlayerList {
+
+ for (int i = 0; i < this.players.size(); ++i) {
+ entityplayer = (ServerPlayer) this.players.get(i);
+- if (entityplayer.getUUID().equals(uuid)) {
++ if (entityplayer.getUUID().equals(uuid) || (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && entityplayer.getGameProfile().getName().equalsIgnoreCase(gameprofile.getName()))) { // Paper - validate usernames
+ list.add(entityplayer);
+ }
+ }
+diff --git a/src/main/java/net/minecraft/util/StringUtil.java b/src/main/java/net/minecraft/util/StringUtil.java
+index e588bd7ef0616dc88ce4c0feeeabadc29dcaa550..6c33002dc8bbb3759c3156302ab7d1f26ce5e8ee 100644
+--- a/src/main/java/net/minecraft/util/StringUtil.java
++++ b/src/main/java/net/minecraft/util/StringUtil.java
+@@ -67,6 +67,25 @@ public class StringUtil {
+ return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
+ }
+
++ // Paper start - Username validation
++ public static boolean isReasonablePlayerName(final String name) {
++ if (name.isEmpty() || name.length() > 16) {
++ return false;
++ }
++
++ for (int i = 0, len = name.length(); i < len; ++i) {
++ final char c = name.charAt(i);
++ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
++ continue;
++ }
++
++ return false;
++ }
++
++ return true;
++ }
++ // Paper end - Username validation
++
+ public static String filterText(String string) {
+ return filterText(string, false);
+ }