From f10b84783013da6f2f0f4afaea64478e13dadb96 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 27 Dec 2022 23:54:59 +0100 Subject: [PATCH] Packet safety in extensions --- .../services/extension_handler/ExtensionHandler.java | 11 +++++++++-- .../extensions/ExtensionListener.java | 2 +- .../ui/subforms/extensions/ExtensionsController.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/ExtensionHandler.java b/G-Earth/src/main/java/gearth/services/extension_handler/ExtensionHandler.java index 61e01b7..87a57d8 100644 --- a/G-Earth/src/main/java/gearth/services/extension_handler/ExtensionHandler.java +++ b/G-Earth/src/main/java/gearth/services/extension_handler/ExtensionHandler.java @@ -200,11 +200,18 @@ public class ExtensionHandler { @Override public void sendMessage(HMessage.Direction direction, HPacket packet) { + boolean success; if (direction == HMessage.Direction.TOCLIENT) { - hConnection.sendToClient(packet); + success = hConnection.sendToClient(packet); } else { - hConnection.sendToServer(packet); + success = hConnection.sendToServer(packet); + } + + if (!success && hConnection.isPacketSendingAllowed(direction, packet) && !hConnection.isPacketSendingSafe(direction, packet)) { + extension.getExtensionObservable().fireEvent(extensionListener -> + extensionListener.log(String.format("Extension %s attempted to send an unsafe packet, but had no permission", + extension.getTitle()))); } } diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/ExtensionListener.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/ExtensionListener.java index 5e90397..59d5942 100644 --- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/ExtensionListener.java +++ b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/ExtensionListener.java @@ -9,7 +9,7 @@ public abstract class ExtensionListener { protected void manipulatedPacket(HMessage hMessage) {} protected void flagsRequest() {} protected void sendMessage(HMessage.Direction direction, HPacket packet) {} - protected void log(String text) {} + public void log(String text) {} protected void hasClosed() {} protected void packetToStringRequest(HPacket packet) {} diff --git a/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java b/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java index d5c01c5..69b6546 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java @@ -75,7 +75,7 @@ public class ExtensionsController extends SubForm { extensionHandler.getObservable().addListener(e -> e.getExtensionObservable().addListener(new ExtensionListener() { @Override - protected void log(String text) { + public void log(String text) { extensionLogger.log(text); } }));