(security) fixed bungeecord InitialHandler username sanitizer

This commit is contained in:
LAX1DUDE 2022-02-19 14:03:45 -08:00
parent 04711c08f7
commit 9f2bcf7e9d
6 changed files with 10 additions and 5 deletions

View file

@ -115,20 +115,25 @@ public class InitialHandler extends PacketHandler implements PendingConnection {
}else if(handshake.getProcolVersion() != 61) { }else if(handshake.getProcolVersion() != 61) {
this.disconnect("minecraft 1.5.2 required for eaglercraft backdoor access"); this.disconnect("minecraft 1.5.2 required for eaglercraft backdoor access");
} }
if (handshake.getUsername().length() < 3) { String un = handshake.getUsername();
if (un.length() < 3) {
this.disconnect("Username must be at least 3 characters"); this.disconnect("Username must be at least 3 characters");
return; return;
} }
if (handshake.getUsername().length() > 16) { if (un.length() > 16) {
this.disconnect("Cannot have username longer than 16 characters"); this.disconnect("Cannot have username longer than 16 characters");
return; return;
} }
if(!un.equals(un.replaceAll("[^A-Za-z0-9\\-_]", "_").trim())) {
this.disconnect("Go fuck yourself");
return;
}
final int limit = BungeeCord.getInstance().config.getPlayerLimit(); final int limit = BungeeCord.getInstance().config.getPlayerLimit();
if (limit > 0 && this.bungee.getOnlineCount() > limit) { if (limit > 0 && this.bungee.getOnlineCount() > limit) {
this.disconnect(this.bungee.getTranslation("proxy_full")); this.disconnect(this.bungee.getTranslation("proxy_full"));
return; return;
} }
if (!BungeeCord.getInstance().config.isOnlineMode() && this.bungee.getPlayer(handshake.getUsername()) != null) { if (!BungeeCord.getInstance().config.isOnlineMode() && this.bungee.getPlayer(un) != null) {
this.disconnect(this.bungee.getTranslation("already_connected")); this.disconnect(this.bungee.getTranslation("already_connected"));
return; return;
} }

View file

@ -2,7 +2,7 @@
#Fri Dec 17 18:41:02 PST 2021 #Fri Dec 17 18:41:02 PST 2021
view-distance=10 view-distance=10
max-build-height=256 max-build-height=256
server-ip= server-ip=127.0.0.1
level-seed= level-seed=
allow-nether=true allow-nether=true
server-port=25569 server-port=25569

View file

@ -25,5 +25,5 @@ permissions:
timeout: 30000 timeout: 30000
servers: servers:
lobby: lobby:
address: localhost:25569 address: 127.0.0.1:25569
restricted: false restricted: false

Binary file not shown.