From d51457c57364ee064a0d76d61d99812cf57c1ab8 Mon Sep 17 00:00:00 2001 From: Paradoks-Studio Date: Mon, 21 Jul 2025 09:54:40 +0200 Subject: [PATCH] Fix: aggressively close stream on invalid headers to prevent potential attacks I was recently targeted by malformed connection attempts sending invalid headers (e.g., "GET "). By aggressively closing the stream immediately inside ReadMessageBlocking when detecting suspicious headers, I reduced server instability and prevented further abuse. This early shutdown avoids leaving the connection open even for a moment longer, mitigating the risk of buffer abuse or resource exhaustion. It worked for me at least. --- Telepathy/ThreadFunctions.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Telepathy/ThreadFunctions.cs b/Telepathy/ThreadFunctions.cs index 066a932..8f8114c 100644 --- a/Telepathy/ThreadFunctions.cs +++ b/Telepathy/ThreadFunctions.cs @@ -68,6 +68,17 @@ public static bool ReadMessageBlocking(NetworkStream stream, int MaxMessageSize, // read exactly 'size' bytes for content (blocking) return stream.ReadExactly(payloadBuffer, size); } + + //PATCH — Aggressive disconnect, close stream immediately to prevent attacker from sending more data before it closes in ReceiveLoop + try + { + stream.Close(); // drop connection before returning + } + catch (Exception ex) + { + Log.Info("Exception while closing stream after header attack: " + ex); + } + Log.Warning("[Telepathy] ReadMessageBlocking: possible header attack with a header of: " + size + " bytes."); return false; } @@ -241,4 +252,4 @@ public static void SendLoop(int connectionId, TcpClient client, MagnificentSendP } } } -} \ No newline at end of file +}