Compare commits

...

2 Commits

Author SHA1 Message Date
YouHaveTrouble 55ee46e167 bump version 2026-08-26 14:11:58 +02:00
OverwriteMC 55b9647890 Validate tab completion requests before exposing command suggestions (#113)
* validate the requested command before exposing argument completions

* fix waterfall tab completion filtering

* some formatting

basic idea formatting wont be bad
2026-08-26 14:06:07 +02:00
9 changed files with 41 additions and 19 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.0</version> <version>2.12.1</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -20,7 +20,10 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public class CommandWhitelistBukkit extends JavaPlugin { public class CommandWhitelistBukkit extends JavaPlugin {
@@ -85,7 +88,8 @@ public class CommandWhitelistBukkit extends JavaPlugin {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
p.updateCommands(); p.updateCommands();
} }
} catch (Exception ignored) {} } catch (Exception ignored) {
}
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded));
}); });
} }
@@ -13,12 +13,13 @@ public class AsyncTabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onCommandTabComplete(AsyncTabCompleteEvent event) { public void onCommandTabComplete(AsyncTabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return; if (!(event.getSender() instanceof Player player)) return;
Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer(); String buffer = event.getBuffer();
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) { int commandEnd = buffer.indexOf(' ');
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)"); if (commandEnd < 0 || buffer.charAt(0) != '/' || !CommandWhitelistBukkit.getCommands(player)
.contains(buffer.substring(1, commandEnd).toLowerCase())) {
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented " + event.getSender().getName() + "'s tab completion (sus packet)");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -13,12 +13,13 @@ public class TabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onCommandTabComplete(TabCompleteEvent event) { public void onCommandTabComplete(TabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return; if (!(event.getSender() instanceof Player player)) return;
Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer(); String buffer = event.getBuffer();
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) { int commandEnd = buffer.indexOf(' ');
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)"); if (commandEnd < 0 || buffer.charAt(0) != '/' || !CommandWhitelistBukkit.getCommands(player)
.contains(buffer.substring(1, commandEnd).toLowerCase())) {
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented " + event.getSender().getName() + "'s tab completion (sus packet)");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.0</version> <version>2.12.1</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.0</version> <version>2.12.1</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.0</version> <version>2.12.1</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <artifactId>Waterfall</artifactId>
@@ -7,19 +7,35 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import java.util.List;
public class BungeeTabcompleteListener implements Listener { public class BungeeTabcompleteListener implements Listener {
@EventHandler @EventHandler
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) { public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
if (!(event.getReceiver() instanceof ProxiedPlayer)) return; if (!(event.getSender() instanceof ProxiedPlayer)) return;
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); ProxiedPlayer player = (ProxiedPlayer) event.getSender();
if (event.getSuggestions().isEmpty()) return;
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
CommandUtil.filterSuggestions(
String cursor = event.getCursor();
int commandEnd = cursor.indexOf(' ');
if (commandEnd >= 0 && cursor.charAt(0) == '/') {
String command = cursor.substring(1, commandEnd).toLowerCase();
if (CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().isExecutableCommand(command, player)
&& !CommandWhitelistWaterfall.getCommands(player).contains(command)) {
event.setCancelled(true);
return;
}
}
if (event.getSuggestions().isEmpty()) return;
List<String> suggestions = CommandUtil.filterSuggestions(
event.getCursor(), event.getCursor(),
event.getSuggestions(), event.getSuggestions(),
CommandWhitelistWaterfall.getSuggestions(player) CommandWhitelistWaterfall.getSuggestions(player)
); );
event.getSuggestions().clear();
event.getSuggestions().addAll(suggestions);
} }
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.0</version> <version>2.12.1</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>