Skip to content

Commit ee5bb40

Browse files
committed
Validate console input before passing it to the server
1 parent 72fc851 commit ee5bb40

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

paper-server/src/main/java/com/destroystokyo/paper/console/PaperConsole.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import io.papermc.paper.configuration.GlobalConfiguration;
44
import io.papermc.paper.console.BrigadierCompletionMatcher;
55
import io.papermc.paper.console.BrigadierConsoleParser;
6+
import net.kyori.adventure.text.Component;
7+
import net.kyori.adventure.text.format.NamedTextColor;
68
import net.minecraft.server.dedicated.DedicatedServer;
9+
import net.minecraft.util.StringUtil;
710
import net.minecrell.terminalconsole.SimpleTerminalConsole;
11+
import org.bukkit.Bukkit;
812
import org.bukkit.craftbukkit.command.ConsoleCommandCompleter;
913
import org.jline.reader.LineReader;
1014
import org.jline.reader.LineReaderBuilder;
@@ -45,10 +49,24 @@ protected void runCommand(String command) {
4549
// terminals interpret pressing [enter] and pasting a multi-line string differently,
4650
// the latter makes the line reader read it as a single line - and we don't want that
4751
// https://github.com/PaperMC/Paper/issues/13006
52+
outer:
4853
for (String line : command.split("\n")) {
4954
if (line.isEmpty()) {
5055
continue;
5156
}
57+
58+
for (char character : line.toCharArray()) {
59+
if (!StringUtil.isAllowedChatCharacter(character)) {
60+
Bukkit.getConsoleSender().sendMessage(
61+
Component.text()
62+
.append(Component.text("Illegal console input character: 0x"))
63+
.append(Component.text(Integer.toHexString(character)))
64+
.color(NamedTextColor.RED)
65+
);
66+
continue outer;
67+
}
68+
}
69+
5270
this.server.handleConsoleInput(line, this.server.createCommandSourceStack());
5371
}
5472
}

0 commit comments

Comments
 (0)