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
|
|
|
|
|
|
|
|
|
2022-01-02 12:51:22 +00:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2022-05-04 22:29:15 +00:00
|
|
|
index c6c9ae9c5217b379ea6ed20f46a81b0e47649a3a..3703e10fe8e33f3d65a38f91b28669de5bc40a5a 100644
|
2022-01-02 12:51:22 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2022-03-12 21:31:21 +00:00
|
|
|
@@ -495,6 +495,12 @@ public class PaperConfig {
|
2022-01-02 12:51:22 +00:00
|
|
|
set("settings.unsupported-settings.allow-tnt-duplication", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static boolean performUsernameValidation;
|
|
|
|
+ private static void performUsernameValidation() {
|
|
|
|
+ performUsernameValidation = getBoolean("settings.unsupported-settings.perform-username-validation", true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
public static int playerAutoSaveRate = -1;
|
|
|
|
public static int maxPlayerAutoSavePerTick = 10;
|
|
|
|
private static void playerAutoSaveRate() {
|
2022-01-01 13:48:17 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2022-03-01 05:43:03 +00:00
|
|
|
index f5c1dff1d571e89f960f11400edbcbbea0620575..7065aa4522431d08018fec8e591ba7c255398140 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-03-01 05:43:03 +00:00
|
|
|
@@ -61,6 +61,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
|
2022-01-18 03:52:47 +00:00
|
|
|
private ServerPlayer delayedAcceptPlayer;
|
|
|
|
public String hostname = ""; // CraftBukkit - add field
|
|
|
|
private int velocityLoginMessageId = -1; // Paper - Velocity support
|
|
|
|
+ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
|
|
|
|
|
|
|
|
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection) {
|
|
|
|
this.state = ServerLoginPacketListenerImpl.State.HELLO;
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -226,11 +227,39 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
|
2022-01-01 13:48:17 +00:00
|
|
|
// Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // 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]);
|
|
|
|
this.gameProfile = packet.getGameProfile();
|
2022-03-01 05:43:03 +00:00
|
|
|
Validate.validState(ServerLoginPacketListenerImpl.isValidUsername(this.gameProfile.getName()), "Invalid characters in username", new Object[0]);
|
2022-01-01 13:48:17 +00:00
|
|
|
+ // Paper start - validate usernames
|
2022-01-02 12:51:22 +00:00
|
|
|
+ if (com.destroystokyo.paper.PaperConfig.isProxyOnlineMode() && com.destroystokyo.paper.PaperConfig.performUsernameValidation) {
|
2022-01-18 03:52:47 +00:00
|
|
|
+ if (!this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation && !validateUsername(this.gameProfile.getName())) {
|
2022-01-01 13:48:17 +00:00
|
|
|
+ ServerLoginPacketListenerImpl.this.disconnect("Failed to verify username!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end - validate usernames
|
|
|
|
if (this.server.usesAuthentication() && !this.connection.isMemoryConnection()) {
|
|
|
|
this.state = ServerLoginPacketListenerImpl.State.KEY;
|
|
|
|
this.connection.send(new ClientboundHelloPacket("", this.server.getKeyPair().getPublic().getEncoded(), this.nonce));
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2022-05-04 22:29:15 +00:00
|
|
|
index ca5026270a44fef244eb566695702bb3f4729367..c88f57256e6f784e39fe74c3b7fc7e3d8b3a618a 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-01-14 03:56:45 +00:00
|
|
|
@@ -707,7 +707,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)) {
|
|
|
|
+ if (entityplayer.getUUID().equals(uuid) || (com.destroystokyo.paper.PaperConfig.isProxyOnlineMode() && entityplayer.getGameProfile().getName().equalsIgnoreCase(gameprofile.getName()))) { // Paper - validate usernames
|
|
|
|
list.add(entityplayer);
|
|
|
|
}
|
|
|
|
}
|