Skip to content

Commit

Permalink
Check for more correct profile validation (#10730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed May 20, 2024
1 parent b3b3406 commit 591521e
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 60 deletions.
14 changes: 12 additions & 2 deletions patches/api/0060-Basic-PlayerProfile-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Buk
index 53f56d95bdf484caed9effbedfe507f6745bb8c0..5aa1aafddd28a5aa52274f37c09bf0fda75f7ea3 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2385,6 +2385,83 @@ public final class Bukkit {
@@ -2385,6 +2385,89 @@ public final class Bukkit {
public static boolean suggestPlayerNamesWhenNullTabCompletions() {
return server.suggestPlayerNamesWhenNullTabCompletions();
}
Expand Down Expand Up @@ -362,6 +362,8 @@ index 53f56d95bdf484caed9effbedfe507f6745bb8c0..5aa1aafddd28a5aa52274f37c09bf0fd
+ *
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name) {
Expand All @@ -386,6 +388,8 @@ index 53f56d95bdf484caed9effbedfe507f6745bb8c0..5aa1aafddd28a5aa52274f37c09bf0fd
+ * @param uuid UUID to create profile for
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
Expand All @@ -406,6 +410,8 @@ index 53f56d95bdf484caed9effbedfe507f6745bb8c0..5aa1aafddd28a5aa52274f37c09bf0fd
+ * @param uuid UUID to create profile for
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
Expand All @@ -418,7 +424,7 @@ diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Ser
index b0734f8253ed540916db7bc75cd7dd24e86031c7..c2cf0e547137b8a023ea009c7a5d0080def5f5f8 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2077,5 +2077,76 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2077,5 +2077,80 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @return true if player names should be suggested
*/
boolean suggestPlayerNamesWhenNullTabCompletions();
Expand Down Expand Up @@ -448,6 +454,8 @@ index b0734f8253ed540916db7bc75cd7dd24e86031c7..c2cf0e547137b8a023ea009c7a5d0080
+ *
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfile(@NotNull String name);
Expand All @@ -471,6 +479,7 @@ index b0734f8253ed540916db7bc75cd7dd24e86031c7..c2cf0e547137b8a023ea009c7a5d0080
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name);
Expand All @@ -490,6 +499,7 @@ index b0734f8253ed540916db7bc75cd7dd24e86031c7..c2cf0e547137b8a023ea009c7a5d0080
+ * @param name Name to create profile for
+ * @return A PlayerProfile object
+ * @throws IllegalArgumentException if the name is longer than 16 characters
+ * @throws IllegalArgumentException if the name contains invalid characters
+ */
+ @NotNull
+ com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name);
Expand Down
8 changes: 4 additions & 4 deletions patches/api/0179-Expose-the-internal-current-tick.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Expose the internal current tick


diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index cddf3250c4a7efe239248b5e9662f33f5c0b702f..836b5d1363ffcff08708b6b4721253ade99eb987 100644
index 2f023dcab9fe1ea220ba04e575bb5efe78adbd45..5d927fe08057d7fe2016f5b019dbbaa647b3ad0e 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2507,6 +2507,10 @@ public final class Bukkit {
@@ -2513,6 +2513,10 @@ public final class Bukkit {
public static com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name) {
return server.createProfileExact(uuid, name);
}
Expand All @@ -20,10 +20,10 @@ index cddf3250c4a7efe239248b5e9662f33f5c0b702f..836b5d1363ffcff08708b6b4721253ad

@NotNull
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 6412546d84874cb93fcdc8426a402bec4e276057..387478b3e4ad9877f3338b719ff447126ef16285 100644
index 6d72b50b12315caf29842b5cf52e67715de8877d..309191a5346ed9b17cf8f3aac9d587400972fda6 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2186,5 +2186,12 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2190,5 +2190,12 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
@NotNull
com.destroystokyo.paper.profile.PlayerProfile createProfileExact(@Nullable UUID uuid, @Nullable String name);
Expand Down
8 changes: 4 additions & 4 deletions patches/api/0186-Expose-MinecraftServer-isRunning.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 1a8f4e122b84b423fe19bfafad56d6d3df9ec134..1c30e523d08250c8a5477fe4d749b779223f069a 100644
index c0f8a858b26768f078ca079010af5544fe6199be..14dee17cfdfcc507d60ba10de3fe6d429dd67654 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2530,6 +2530,15 @@ public final class Bukkit {
@@ -2536,6 +2536,15 @@ public final class Bukkit {
public static int getCurrentTick() {
return server.getCurrentTick();
}
Expand All @@ -26,10 +26,10 @@ index 1a8f4e122b84b423fe19bfafad56d6d3df9ec134..1c30e523d08250c8a5477fe4d749b779

@NotNull
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index fc4e259e5ca7a4b25f276bda7f2f5ea022d0c552..1f4ebdaf9cfd14de9ff2d0cea7d110fe7630dc9a 100644
index e3fbaecb6f50e4daccde3df3657ae0a4dadf5688..5846bcd03e34b02b0c4dc0a1edca37cc62d0ac29 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2208,5 +2208,12 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2212,5 +2212,12 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @return Current tick
*/
int getCurrentTick();
Expand Down
8 changes: 4 additions & 4 deletions patches/api/0192-Add-Mob-Goal-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ index 0000000000000000000000000000000000000000..e21f7574763dd4f13794f91bbef192ef
+ <T extends Mob> Collection<Goal<T>> getRunningGoalsWithout(@NotNull T mob, @NotNull GoalType type);
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 1c30e523d08250c8a5477fe4d749b779223f069a..f2fa4c419f212ea5d7ca0aab4ead4bd44dac5947 100644
index 14dee17cfdfcc507d60ba10de3fe6d429dd67654..bd711e43abb012065dbefa911347a47c2aa4933a 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2539,6 +2539,16 @@ public final class Bukkit {
@@ -2545,6 +2545,16 @@ public final class Bukkit {
public static boolean isStopping() {
return server.isStopping();
}
Expand All @@ -247,10 +247,10 @@ index 1c30e523d08250c8a5477fe4d749b779223f069a..f2fa4c419f212ea5d7ca0aab4ead4bd4

@NotNull
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 1f4ebdaf9cfd14de9ff2d0cea7d110fe7630dc9a..711de014b7cf69459526e6c20c94f29ee4db11c4 100644
index 5846bcd03e34b02b0c4dc0a1edca37cc62d0ac29..755d68961171fc6c520e9f8ee908c99c1f404584 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2215,5 +2215,13 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2219,5 +2219,13 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @return true if server is in the process of being shutdown
*/
boolean isStopping();
Expand Down
8 changes: 4 additions & 4 deletions patches/api/0275-Add-basic-Datapack-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ index 0000000000000000000000000000000000000000..58f78d5e91beacaf710f62461cf869f7
+
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 94abdf67a057ef02fc98b61c1b9376454cc5b4c8..e5a9b816b281017a08959d8e61acf59574dc1c50 100644
index 149c1a1cc39f79ca03e1f02cf2751885e0428895..4d8ff5b400a17fadefc25b3bf602eadb12cae4e9 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -327,9 +327,11 @@ public final class Bukkit {
Expand All @@ -85,7 +85,7 @@ index 94abdf67a057ef02fc98b61c1b9376454cc5b4c8..e5a9b816b281017a08959d8e61acf595
public static DataPackManager getDataPackManager() {
return server.getDataPackManager();
}
@@ -2585,6 +2587,14 @@ public final class Bukkit {
@@ -2591,6 +2593,14 @@ public final class Bukkit {
public static com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
return server.getMobGoals();
}
Expand All @@ -101,7 +101,7 @@ index 94abdf67a057ef02fc98b61c1b9376454cc5b4c8..e5a9b816b281017a08959d8e61acf595

@NotNull
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index e1ab2090c1b219f12af382079907e440e9cf4379..e3a494b9d3727973d225de3042da93594f36ca12 100644
index 0c71aa3b5758dbfdce8782e02772f9450901adbd..2fa562ca863810cbba82d43bf452f61d9e02cfdb 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -266,9 +266,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
Expand All @@ -116,7 +116,7 @@ index e1ab2090c1b219f12af382079907e440e9cf4379..e3a494b9d3727973d225de3042da9359
public DataPackManager getDataPackManager();

/**
@@ -2256,5 +2258,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2260,5 +2262,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
@NotNull
com.destroystokyo.paper.entity.ai.MobGoals getMobGoals();
Expand Down
8 changes: 4 additions & 4 deletions patches/api/0342-Custom-Potion-Mixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ index 0000000000000000000000000000000000000000..3ede1e8f7bf0436fdc5bf395c0f9eaf1
+ }
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index f11b60d888e8f3a0c6213078cb5db35eafb82e3f..84d43e24a69352e2715935fd7ce3fd05aaca8601 100644
index e224a28f1c81ca3439c9618d46ad53f8af8c760c..93012c264b6a509b0c3df26896136cb5c1ffc264 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2627,6 +2627,15 @@ public final class Bukkit {
@@ -2633,6 +2633,15 @@ public final class Bukkit {
public static io.papermc.paper.datapack.DatapackManager getDatapackManager() {
return server.getDatapackManager();
}
Expand All @@ -175,10 +175,10 @@ index f11b60d888e8f3a0c6213078cb5db35eafb82e3f..84d43e24a69352e2715935fd7ce3fd05

@NotNull
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 31eaec316e0ee4021d0a67301d1bc91a2d3524d9..88ad9e596f801c2c137fe2d31653a841b9c01683 100644
index d1fb5010a8a1526a24be26c0d6330800fd54e184..082969ca7babe5f1158a11a7f6f2fb220eb912eb 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2292,5 +2292,12 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2296,5 +2296,12 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
@NotNull
io.papermc.paper.datapack.DatapackManager getDatapackManager();
Expand Down
8 changes: 4 additions & 4 deletions patches/api/0405-Folia-scheduler-and-owned-region-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,10 @@ index 0000000000000000000000000000000000000000..a6b50c9d8af589cc4747e14d343d2045
+ }
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 49c027f2c78660594caa51341291b1bcd35b8993..290d692fccf63c5f109b8a3f1de726a12a20ddc9 100644
index 74ae33a6465f0a63b599527e9b7b3ed2d388d624..37b3d1aceaf6522f712cb6ec8a8b7f5689eb1852 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2658,6 +2658,141 @@ public final class Bukkit {
@@ -2664,6 +2664,141 @@ public final class Bukkit {
}
// Paper end

Expand Down Expand Up @@ -645,10 +645,10 @@ index 49c027f2c78660594caa51341291b1bcd35b8993..290d692fccf63c5f109b8a3f1de726a1
public static Server.Spigot spigot() {
return server.spigot();
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index c1a46d13e61140c851f73f2ee7c6cec24ba8b3fa..954c8422567edcf6bf6db153b65dad776eea654f 100644
index e9a97ee5c086ebb48ebc3d9bca406f32380d28cb..871696b6c7363efc7020f4ac7f6b7437f06191ae 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2321,4 +2321,119 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2325,4 +2325,119 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
@NotNull org.bukkit.potion.PotionBrewer getPotionBrewer();
// Paper end
Expand Down
10 changes: 6 additions & 4 deletions patches/server/0072-Handle-Item-Meta-Inconsistencies.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 591521e

Please sign in to comment.