Check for more correct profile validation (#10730)

This commit is contained in:
Jake Potrebic
2024-05-19 17:45:43 -07:00
parent 3fb22e8951
commit 763f42fc65
4 changed files with 19 additions and 8 deletions

View File

@@ -362,6 +362,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * + *
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */ + */
+ @NotNull + @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name) { + public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name) {
@@ -386,6 +388,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param uuid UUID to create profile for + * @param uuid UUID to create profile for
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */ + */
+ @NotNull + @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) { + public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
@@ -406,6 +410,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param uuid UUID to create profile for + * @param uuid UUID to create profile for
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */ + */
+ @NotNull + @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) { + public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
@@ -448,6 +454,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * + *
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */ + */
+ @NotNull + @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name); + com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name);
@@ -471,6 +479,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */ + */
+ @NotNull + @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name); + com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name);
@@ -490,6 +499,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param name Name to create profile for + * @param name Name to create profile for
+ * @return A PlayerProfile object + * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters + * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */ + */
+ @NotNull + @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name); + com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name);

View File

@@ -33,6 +33,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import net.minecraft.Util; +import net.minecraft.Util;
+import net.minecraft.server.MinecraftServer; +import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.players.GameProfileCache; +import net.minecraft.server.players.GameProfileCache;
+import net.minecraft.util.StringUtil;
+import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.Validate;
+import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.configuration.serialization.SerializableAs;
@@ -292,6 +293,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ private static GameProfile createAuthLibProfile(UUID uniqueId, String name) { + 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 || 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( + return new GameProfile(
+ uniqueId != null ? uniqueId : Util.NIL_UUID, + uniqueId != null ? uniqueId : Util.NIL_UUID,
+ name != null ? name : "" + name != null ? name : ""
@@ -678,12 +680,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player); + return new com.destroystokyo.paper.profile.CraftPlayerProfile((CraftPlayer) player);
+ } + }
+ +
+ final com.mojang.authlib.GameProfile profile = new com.mojang.authlib.GameProfile( + final com.destroystokyo.paper.profile.CraftPlayerProfile profile = new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
+ uuid != null ? uuid : net.minecraft.Util.NIL_UUID, + profile.getGameProfile().getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
+ name != null ? name : "" + return profile;
+ );
+ profile.getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(profile);
+ } + }
// Paper end // Paper end
} }

View File

@@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -0,0 +0,0 @@ public final class CraftServer implements Server { @@ -0,0 +0,0 @@ public final class CraftServer implements Server {
profile.getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties()); profile.getGameProfile().getProperties().putAll(((CraftPlayer) player).getHandle().getGameProfile().getProperties());
return new com.destroystokyo.paper.profile.CraftPlayerProfile(profile); return profile;
} }
+ +
+ @Override + @Override

View File

@@ -273,6 +273,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
Preconditions.checkArgument(isValidSkullProfile, "The skull profile is missing a name or textures!"); Preconditions.checkArgument(isValidSkullProfile, "The skull profile is missing a name or textures!");
+ // Paper start - Validate + // Paper start - Validate
+ Preconditions.checkArgument(gameProfile.getName().length() <= 16, "The name of the profile is longer than 16 characters"); + 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(); + final PropertyMap properties = gameProfile.getProperties();
+ Preconditions.checkArgument(properties.size() <= 16, "The profile contains more than 16 properties"); + Preconditions.checkArgument(properties.size() <= 16, "The profile contains more than 16 properties");
+ for (final Property property : properties.values()) { + for (final Property property : properties.values()) {
@@ -289,6 +290,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public CraftPlayerProfile(UUID uniqueId, String name) { public CraftPlayerProfile(UUID uniqueId, String name) {
Preconditions.checkArgument((uniqueId != null) || !StringUtils.isBlank(name), "uniqueId is null or name is blank"); 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 || 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.uniqueId = (uniqueId == null) ? Util.NIL_UUID : uniqueId;
this.name = (name == null) ? "" : name; this.name = (name == null) ? "" : name;
} }