Skip to content

Commit 375a114

Browse files
committed
Validate console input before passing it to the server
1 parent b9923b9 commit 375a114

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 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,12 +49,23 @@ 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
48-
for (String line : command.split("\n")) {
49-
if (line.isEmpty()) {
50-
continue;
51-
}
52-
this.server.handleConsoleInput(line, this.server.createCommandSourceStack());
53-
}
52+
command.lines()
53+
.filter(line -> !line.isEmpty())
54+
.forEach(line -> {
55+
for (char character : line.toCharArray()) {
56+
if (!StringUtil.isAllowedChatCharacter(character)) {
57+
Bukkit.getConsoleSender().sendMessage(
58+
Component.text()
59+
.append(Component.text("Illegal console input character: 0x"))
60+
.append(Component.text(Integer.toHexString(character)))
61+
.color(NamedTextColor.RED)
62+
);
63+
return;
64+
}
65+
}
66+
67+
this.server.handleConsoleInput(line, this.server.createCommandSourceStack());
68+
});
5469
}
5570

5671
@Override

0 commit comments

Comments
 (0)