2022-01-01 13:48:17 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
|
|
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
|
2022-10-02 07:56:36 +00:00
|
|
|
index b87bd1c2d3a371e2fca1d0bff6d0985188b22584..64e2004e023f79d28c400f7182b0ffa93789620d 100644
|
2022-01-01 13:48:17 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2022-08-08 15:25:41 +00:00
|
|
|
@@ -66,6 +66,7 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se
|
|
|
|
@Nullable
|
2022-07-27 21:32:15 +00:00
|
|
|
private ProfilePublicKey.Data profilePublicKeyData;
|
2022-01-18 03:52:47 +00:00
|
|
|
public String hostname = ""; // CraftBukkit - add field
|
|
|
|
+ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
|
|
|
|
|
|
|
|
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection) {
|
|
|
|
this.state = ServerLoginPacketListenerImpl.State.HELLO;
|
2022-09-17 21:58:51 +00:00
|
|
|
@@ -245,10 +246,38 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se
|
2022-06-08 12:33:46 +00:00
|
|
|
}
|
2022-01-01 13:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - validate usernames
|
|
|
|
+ public static boolean validateUsername(String in) {
|
|
|
|
+ if (in == null || in.isEmpty() || in.length() > 16) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0, len = in.length(); i < len; ++i) {
|
|
|
|
+ char c = in.charAt(i);
|
|
|
|
+
|
2022-01-01 19:50:44 +00:00
|
|
|
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
|
2022-01-01 13:48:17 +00:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // Paper end - validate usernames
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public void handleHello(ServerboundHelloPacket packet) {
|
|
|
|
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
|
2022-06-08 12:33:46 +00:00
|
|
|
Validate.validState(ServerLoginPacketListenerImpl.isValidUsername(packet.name()), "Invalid characters in username", new Object[0]);
|
2022-01-01 13:48:17 +00:00
|
|
|
+ // Paper start - validate usernames
|
2022-06-09 08:51:45 +00:00
|
|
|
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation) {
|
2022-06-08 12:33:46 +00:00
|
|
|
+ if (!this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation && !validateUsername(packet.name())) {
|
2022-01-01 13:48:17 +00:00
|
|
|
+ ServerLoginPacketListenerImpl.this.disconnect("Failed to verify username!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end - validate usernames
|
2022-07-27 21:32:15 +00:00
|
|
|
this.profilePublicKeyData = (ProfilePublicKey.Data) packet.publicKey().orElse(null); // CraftBukkit - decompile error
|
|
|
|
GameProfile gameprofile = this.server.getSingleplayerProfile();
|
2022-06-08 12:33:46 +00:00
|
|
|
|
2022-01-01 13:48:17 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2022-09-26 08:02:51 +00:00
|
|
|
index 4277f7fdd8f27e57708a8dee59bf1b9052a1ebe4..133bf27e301aa5815cc7d7e275b2b08cdc6e4392 100644
|
2022-01-01 13:48:17 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2022-09-01 16:51:59 +00:00
|
|
|
@@ -714,7 +714,7 @@ public abstract class PlayerList {
|
2022-01-01 13:48:17 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < this.players.size(); ++i) {
|
|
|
|
entityplayer = (ServerPlayer) this.players.get(i);
|
|
|
|
- if (entityplayer.getUUID().equals(uuid)) {
|
2022-06-09 08:51:45 +00:00
|
|
|
+ if (entityplayer.getUUID().equals(uuid) || (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && entityplayer.getGameProfile().getName().equalsIgnoreCase(gameprofile.getName()))) { // Paper - validate usernames
|
2022-01-01 13:48:17 +00:00
|
|
|
list.add(entityplayer);
|
|
|
|
}
|
|
|
|
}
|