From 4c612e3890583bef1c7cda117cca1331b2e0c865 Mon Sep 17 00:00:00 2001 From: oliveratgithub Date: Tue, 2 Dec 2025 00:34:41 +0100 Subject: [PATCH 1/2] telegram(updateHandler): Restricts message access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discards any Messages form non-bridged Telegram Chat IDs the Bot «can read», but are not in scope. Better early prevention to process any arbitrary messages or objects. Allows reusing an existing Telegram Bot, which is connected to multiple Chats. Could also make the last step of the Quick Start Guide «Create bot with BotFather» obsolete / less critical: ~Send /setjoingroups to @BotFather, change to Disable~ --- internal/handlers/telegram/handler.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/handlers/telegram/handler.go b/internal/handlers/telegram/handler.go index 021f49d..167618e 100644 --- a/internal/handlers/telegram/handler.go +++ b/internal/handlers/telegram/handler.go @@ -21,6 +21,13 @@ which handler to fire off */ func updateHandler(tg *Client, updates tgbotapi.UpdatesChannel) { for u := range updates { + // Don't process any messages that didn't come from the + // chat we're bridging + if u.Message.Chat.ID != tg.Settings.ChatID { + tg.logger.LogDebug("Ignored message from a telegram chat we're not bridging:", tg.Settings.ChatID) + continue + } + switch { case u.Message == nil: tg.logger.LogError("Missing message data") @@ -66,12 +73,6 @@ func messageHandler(tg *Client, u tgbotapi.Update) { return } - // Don't forward messages to IRC that didn't come from the - // chat we're bridging - if u.Message.Chat.ID != tg.Settings.ChatID { - return - } - // Telegram user replied to a message if u.Message.ReplyToMessage != nil { replyHandler(tg, u) From a5c1c9f8fcbb09a6deb0eba640fce604a7cfba64 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 19 May 2026 21:17:59 +0200 Subject: [PATCH 2/2] fix(updateHandler): panic: runtime error Ignored message from a telegram chat we're not bridging: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x6bd6b9] --- internal/handlers/telegram/handler.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/handlers/telegram/handler.go b/internal/handlers/telegram/handler.go index 167618e..42c7404 100644 --- a/internal/handlers/telegram/handler.go +++ b/internal/handlers/telegram/handler.go @@ -21,16 +21,16 @@ which handler to fire off */ func updateHandler(tg *Client, updates tgbotapi.UpdatesChannel) { for u := range updates { - // Don't process any messages that didn't come from the - // chat we're bridging - if u.Message.Chat.ID != tg.Settings.ChatID { - tg.logger.LogDebug("Ignored message from a telegram chat we're not bridging:", tg.Settings.ChatID) - continue - } - switch { case u.Message == nil: - tg.logger.LogError("Missing message data") + // Non-message updates (edited messages, reactions, polls, inline + // queries, channel posts, etc.) are normal; skip silently. + tg.logger.LogDebug("Skipping non-message Telegram update") + continue + case u.Message.Chat.ID != tg.Settings.ChatID: + // Don't process any messages that didn't come from the + // chat we're bridging + tg.logger.LogDebug("Ignored message from a telegram chat we're not bridging:", u.Message.Chat.ID) continue case u.Message.NewChatMembers != nil: tg.logger.LogDebug("joinHandler triggered")