Check for more correct profile validation (#10730)

This commit is contained in:
Jake Potrebic 2024-05-19 17:45:43 -07:00 committed by GitHub
parent b3b340617e
commit 591521e697
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 71 additions and 60 deletions

View file

@ -264,15 +264,16 @@ index 9e23cdef8bd166937093452009f50b86e683cc57..a052c2dab5af99355737a88f75cb0b2e
+
}
diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
index 358af0121ce3d87a9f51da2bae0699034c1560b4..44174c5a7b255af489c1e4bf589299e6bdbb90a3 100644
index 358af0121ce3d87a9f51da2bae0699034c1560b4..94cae8f3c13d0afcbe97478fba34ff4f12f8c7ee 100644
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
@@ -37,6 +37,16 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -37,6 +37,17 @@ public final class CraftPlayerProfile implements PlayerProfile {
boolean isValidSkullProfile = (gameProfile.getName() != null)
|| gameProfile.getProperties().containsKey(CraftPlayerTextures.PROPERTY_NAME);
Preconditions.checkArgument(isValidSkullProfile, "The skull profile is missing a name or textures!");
+ // Paper start - Validate
+ Preconditions.checkArgument(gameProfile.getName().length() <= 16, "The name of the profile is longer than 16 characters");
+ Preconditions.checkArgument(net.minecraft.util.StringUtil.isValidPlayerName(gameProfile.getName()), "The name of the profile contains invalid characters: %s", gameProfile.getName());
+ final PropertyMap properties = gameProfile.getProperties();
+ Preconditions.checkArgument(properties.size() <= 16, "The profile contains more than 16 properties");
+ for (final Property property : properties.values()) {
@ -284,15 +285,16 @@ index 358af0121ce3d87a9f51da2bae0699034c1560b4..44174c5a7b255af489c1e4bf589299e6
return gameProfile;
}
@@ -53,6 +63,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -53,6 +64,8 @@ public final class CraftPlayerProfile implements PlayerProfile {
public CraftPlayerProfile(UUID uniqueId, String name) {
Preconditions.checkArgument((uniqueId != null) || !StringUtils.isBlank(name), "uniqueId is null or name is blank");
+ Preconditions.checkArgument(name == null || name.length() <= 16, "The name of the profile is longer than 16 characters"); // Paper - Validate
+ Preconditions.checkArgument(name == null || net.minecraft.util.StringUtil.isValidPlayerName(name), "The name of the profile contains invalid characters: %s", name); // Paper - Validate
this.uniqueId = (uniqueId == null) ? Util.NIL_UUID : uniqueId;
this.name = (name == null) ? "" : name;
}
@@ -89,6 +100,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -89,6 +102,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
// Assert: (property == null) || property.getName().equals(propertyName)
this.removeProperty(propertyName);
if (property != null) {

View file

@ -66,7 +66,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.jav
index 44174c5a7b255af489c1e4bf589299e6bdbb90a3..ab18b1d480f7ecc0ad9a51471d8f45b0da74d8cf 100644
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
@@ -134,7 +134,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -136,7 +136,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public CompletableFuture<PlayerProfile> update() {

View file

@ -16,10 +16,10 @@ public org.bukkit.craftbukkit.profile.CraftPlayerProfile setProperty(Ljava/lang/
diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
new file mode 100644
index 0000000000000000000000000000000000000000..72e232791efa2154c6c95d2158734a86480cb40d
index 0000000000000000000000000000000000000000..cbe2789f8a055550dd7840a7bed980efd65eb9a1
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
@@ -0,0 +1,420 @@
@@ -0,0 +1,422 @@
+package com.destroystokyo.paper.profile;
+
+import com.google.common.base.Preconditions;
@ -33,6 +33,7 @@ index 0000000000000000000000000000000000000000..72e232791efa2154c6c95d2158734a86
+import net.minecraft.Util;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.players.GameProfileCache;
+import net.minecraft.util.StringUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate;
+import org.bukkit.configuration.serialization.SerializableAs;
@ -292,6 +293,7 @@ index 0000000000000000000000000000000000000000..72e232791efa2154c6c95d2158734a86
+
+ private static GameProfile createAuthLibProfile(UUID uniqueId, String name) {
+ Preconditions.checkArgument(name == null || name.length() <= 16, "Name cannot be longer than 16 characters");
+ Preconditions.checkArgument(name == null || StringUtil.isValidPlayerName(name), "The name of the profile contains invalid characters: %s", name);
+ return new GameProfile(
+ uniqueId != null ? uniqueId : Util.NIL_UUID,
+ name != null ? name : ""
@ -644,7 +646,7 @@ index 02308021712a2e947bd389e625b5d93e62f5024b..f7c258b6f0f4eb6094828da20e4a5af2
CraftItemFactory.instance();
CraftEntityFactory.instance();
}
@@ -2804,5 +2808,42 @@ public final class CraftServer implements Server {
@@ -2804,5 +2808,39 @@ public final class CraftServer implements Server {
public boolean suggestPlayerNamesWhenNullTabCompletions() {
return io.papermc.paper.configuration.GlobalConfiguration.get().commands.suggestPlayerNamesWhenNullTabCompletions;
}
@ -678,17 +680,14 @@ index 02308021712a2e947bd389e625b5d93e62f5024b..f7c258b6f0f4eb6094828da20e4a5af2
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player);
+ }
+
+ final com.mojang.authlib.GameProfile profile = new com.mojang.authlib.GameProfile(
+ uuid != null ? uuid : net.minecraft.Util.NIL_UUID,
+ name != null ? name : ""
+ );
+ profile.getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(profile);
+ final com.destroystokyo.paper.profile.CraftPlayerProfile profile = new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
+ profile.getGameProfile().getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
+ return profile;
+ }
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
index ab18b1d480f7ecc0ad9a51471d8f45b0da74d8cf..d2c121cc610b6c635e2de5059b147f5ee35096bd 100644
index c49db689827b20ad211f06b9bad7062c8ef82c68..ce30a8853d5095ce5bf1ec902b41d27db9e35b4f 100644
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
@@ -28,7 +28,7 @@ import org.bukkit.profile.PlayerProfile;
@ -700,7 +699,7 @@ index ab18b1d480f7ecc0ad9a51471d8f45b0da74d8cf..d2c121cc610b6c635e2de5059b147f5e
@Nonnull
public static GameProfile validateSkullProfile(@Nonnull GameProfile gameProfile) {
@@ -105,8 +105,10 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -107,8 +107,10 @@ public final class CraftPlayerProfile implements PlayerProfile {
}
}
@ -713,7 +712,7 @@ index ab18b1d480f7ecc0ad9a51471d8f45b0da74d8cf..d2c121cc610b6c635e2de5059b147f5e
}
void rebuildDirtyProperties() {
@@ -249,6 +251,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -251,6 +253,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@Override
public Map<String, Object> serialize() {
@ -721,7 +720,7 @@ index ab18b1d480f7ecc0ad9a51471d8f45b0da74d8cf..d2c121cc610b6c635e2de5059b147f5e
Map<String, Object> map = new LinkedHashMap<>();
if (this.getUniqueId() != null) {
map.put("uniqueId", this.getUniqueId().toString());
@@ -264,10 +267,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -266,10 +269,12 @@ public final class CraftPlayerProfile implements PlayerProfile {
});
map.put("properties", propertiesData);
}
@ -734,7 +733,7 @@ index ab18b1d480f7ecc0ad9a51471d8f45b0da74d8cf..d2c121cc610b6c635e2de5059b147f5e
UUID uniqueId = ConfigSerializationUtil.getUuid(map, "uniqueId", true);
String name = ConfigSerializationUtil.getString(map, "name", true);
@@ -281,7 +286,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
@@ -283,7 +288,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
profile.properties.put(property.name(), property);
}
}

View file

@ -5,12 +5,12 @@ Subject: [PATCH] Expose the internal current tick
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 32765f19f6cd4973b4d2d8085637124f8192373c..11ef05f685b040f90988436bd07b1e747777dbb8 100644
index eb178edff9fa0d2be549e2fa62a8ddfd7fd73f83..383f38cd8436fa8efaff53d235b0ad9f757c5c0b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2882,5 +2882,10 @@ public final class CraftServer implements Server {
profile.getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
return new com.destroystokyo.paper.profile.CraftPlayerProfile(profile);
@@ -2879,5 +2879,10 @@ public final class CraftServer implements Server {
profile.getGameProfile().getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
return profile;
}
+
+ @Override

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Expose MinecraftServer#isRunning
This allows for plugins to detect if the server is actually turning off in onDisable rather than just plugins reloading.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 6e10244fe14d6271c0215c09a6df3f55a3ca6ade..8e082ec92c437e27d71e70a91a0bf65153de29a3 100644
index 69c10ac5f54141fe8afeef79df287ab694f2b033..2b096d8594b71261fe7166664574532fe7009a2a 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2897,5 +2897,10 @@ public final class CraftServer implements Server {
@@ -2894,5 +2894,10 @@ public final class CraftServer implements Server {
public int getCurrentTick() {
return net.minecraft.server.MinecraftServer.currentTick;
}

View file

@ -773,10 +773,10 @@ index 6667ecc4b7eded4e20a415cef1e1b1179e6710b8..16f9a98b8a939e5ca7e2dc04f87134a7
LOOK,
JUMP,
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 26bebc3ddd15e963e818011556f216f275bd7415..8e0e38bc85ca97f4c632299affc366ece7e63a52 100644
index cd6fb7eb121c527e798219177781c13097fd9ef6..c6a96664ef914d0da1e24b93da93bad1b4a17716 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2903,5 +2903,11 @@ public final class CraftServer implements Server {
@@ -2900,5 +2900,11 @@ public final class CraftServer implements Server {
public boolean isStopping() {
return net.minecraft.server.MinecraftServer.getServer().hasStopped();
}

View file

@ -92,7 +92,7 @@ index 0000000000000000000000000000000000000000..cf4374493c11057451a62a655514415c
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 1f6218e580a2a0138d128940a709147c20354b39..c4e63ba96a54fb9e1353510f77d848bed3656405 100644
index 6fbb452b583d5b5ab95a057a7e6ed17d2e6a2b15..2098ea8dcdf8e3a704db972192993cbc616d7dac 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -301,6 +301,7 @@ public final class CraftServer implements Server {
@ -111,7 +111,7 @@ index 1f6218e580a2a0138d128940a709147c20354b39..c4e63ba96a54fb9e1353510f77d848be
}
public boolean getCommandBlockOverride(String command) {
@@ -2971,5 +2973,11 @@ public final class CraftServer implements Server {
@@ -2968,5 +2970,11 @@ public final class CraftServer implements Server {
public com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
return mobGoals;
}

View file

@ -282,7 +282,7 @@ index 3ebfd564d4bbf00da5919e966f3d047285845640..887957ce1ddc2f32569405642f35df46
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 9790cff70cf006c35dbfe95653a1bacdea33607d..0ed2d510918cc14ce3d7e5def2021e07f7ad378f 100644
index 151340a41adbdf9effe78aed8122abfaf54d9b7a..2f550747f605e27b9fe968c94ae37aa265624462 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -304,6 +304,7 @@ public final class CraftServer implements Server {
@ -301,7 +301,7 @@ index 9790cff70cf006c35dbfe95653a1bacdea33607d..0ed2d510918cc14ce3d7e5def2021e07
datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper
}
@@ -3095,5 +3097,9 @@ public final class CraftServer implements Server {
@@ -3092,5 +3094,9 @@ public final class CraftServer implements Server {
return datapackManager;
}

View file

@ -256,7 +256,7 @@ index 7522a31d618e90d5109f3067e07748f9a07482a5..7dfad8abaf5db2ca5ea942a0ce92c331
}
diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
index d2c121cc610b6c635e2de5059b147f5ee35096bd..3e725dd3aca80a062917e3fd214c554b52dddde5 100644
index ce30a8853d5095ce5bf1ec902b41d27db9e35b4f..0121c90dd7f57be5f484f970f78747a92a734611 100644
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
@@ -28,7 +28,7 @@ import org.bukkit.profile.PlayerProfile;
@ -268,7 +268,7 @@ index d2c121cc610b6c635e2de5059b147f5ee35096bd..3e725dd3aca80a062917e3fd214c554b
@Nonnull
public static GameProfile validateSkullProfile(@Nonnull GameProfile gameProfile) {
@@ -135,7 +135,7 @@ public final class CraftPlayerProfile implements PlayerProfile, com.destroystoky
@@ -137,7 +137,7 @@ public final class CraftPlayerProfile implements PlayerProfile, com.destroystoky
}
@Override
@ -277,7 +277,7 @@ index d2c121cc610b6c635e2de5059b147f5ee35096bd..3e725dd3aca80a062917e3fd214c554b
return CompletableFuture.supplyAsync(this::getUpdatedProfile, Util.PROFILE_EXECUTOR); // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
}
@@ -289,4 +289,71 @@ public final class CraftPlayerProfile implements PlayerProfile, com.destroystoky
@@ -291,4 +291,71 @@ public final class CraftPlayerProfile implements PlayerProfile, com.destroystoky
// Paper - diff on change
return profile;
}