From ad50fc9ad324d934e33dc47255359ef28712ba45 Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Tue, 15 Jun 2021 09:06:33 +1000 Subject: [PATCH] #3111: Check chat for illegal chars & moved length check into the packet class --- .../main/java/net/md_5/bungee/protocol/packet/Chat.java | 2 +- .../java/net/md_5/bungee/connection/UpstreamBridge.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java index e3a4d250..11b04c2a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java @@ -40,7 +40,7 @@ public class Chat extends DefinedPacket @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - message = readString( buf, ( direction == ProtocolConstants.Direction.TO_CLIENT ) ? 262144 : 256 ); + message = readString( buf, ( direction == ProtocolConstants.Direction.TO_CLIENT ) ? 262144 : ( protocolVersion >= ProtocolConstants.MINECRAFT_1_11 ? 256 : 100 ) ); if ( direction == ProtocolConstants.Direction.TO_CLIENT ) { position = buf.readByte(); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index f150d8fa..5f7f3c4d 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -144,8 +144,11 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(Chat chat) throws Exception { - int maxLength = ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_11 ) ? 256 : 100; - Preconditions.checkArgument( chat.getMessage().length() <= maxLength, "Chat message too long" ); // Mojang limit, check on updates + for ( int index = 0, length = chat.getMessage().length(); index < length; index++ ) + { + char c = chat.getMessage().charAt( index ); + Preconditions.checkArgument( c != '\u00A7' && c >= ' ' && c != 127, "illegal characters in chat" ); // Section symbol, control sequences, and delete + } ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() ); if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() )