From 31800bcebc22a075fe47ff43986a05ad27956a41 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:32:49 +0200 Subject: [PATCH] Fix forcelogin auth exploit --- .../listener/data/PluginMessageListener.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java index 53c3d21..e27ece5 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java @@ -58,15 +58,20 @@ public final class PluginMessageListener implements Listener public EventTask executeAsync(final PluginMessageEvent event) { return EventTask.async(() -> { plugin.logDebug(() -> "PluginMessageEvent | Start"); - if (notAllowedEvent(event)) { - plugin.logDebug(() -> "PluginMessageEvent | Not allowed"); + if (notHandledEvent(event)) { + plugin.logDebug(() -> "PluginMessageEvent | Not handled"); return; } - final ServerConnection connection = (ServerConnection) event.getSource(); - + // Set the result to handled, the message is dropped at the proxy event.setResult(PluginMessageEvent.ForwardResult.handled()); + // Make sure the message is S -> P, NOT P -> S + if (!(event.getSource() instanceof ServerConnection connection)) { + plugin.logDebug("PluginMessageEvent | Not ServerConnection"); + return; + } + final ByteArrayDataInput input = event.dataAsDataStream(); final String message = input.readUTF(); final MessageType type = TYPES.valueOrThrow(message.toUpperCase(Locale.ROOT)); @@ -114,15 +119,11 @@ public final class PluginMessageListener implements Listener }); } - private boolean notAllowedEvent(PluginMessageEvent event) { + private boolean notHandledEvent(PluginMessageEvent event) { if (!event.getResult().isAllowed()) { plugin.logDebug("PluginMessageEvent | Result not allowed"); return true; } - if (!(event.getSource() instanceof ServerConnection)) { - plugin.logDebug("PluginMessageEvent | Not ServerConnection"); - return true; - } final var identifier = event.getIdentifier(); if (!(identifier.equals(AuthMeVelocityPlugin.MODERN_CHANNEL) || identifier.equals(AuthMeVelocityPlugin.LEGACY_CHANNEL))) {