#3111: Check chat for illegal chars & moved length check into the packet class

This commit is contained in:
Outfluencer 2021-06-15 09:06:33 +10:00 committed by md_5
parent a25c2b325b
commit ad50fc9ad3
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 6 additions and 3 deletions

View File

@ -40,7 +40,7 @@ public class Chat extends DefinedPacket
@Override @Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) 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 ) if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{ {
position = buf.readByte(); position = buf.readByte();

View File

@ -144,8 +144,11 @@ public class UpstreamBridge extends PacketHandler
@Override @Override
public void handle(Chat chat) throws Exception public void handle(Chat chat) throws Exception
{ {
int maxLength = ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_11 ) ? 256 : 100; for ( int index = 0, length = chat.getMessage().length(); index < length; index++ )
Preconditions.checkArgument( chat.getMessage().length() <= maxLength, "Chat message too long" ); // Mojang limit, check on updates {
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() ); ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() );
if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() )