From c0fe4a16df03b24a835f2a5bd9c8b812e4830d53 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 24 Aug 2023 14:22:22 +0300 Subject: [PATCH] Improve suspicious data detection --- user.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/user.go b/user.go index 9aa7172..114d43b 100644 --- a/user.go +++ b/user.go @@ -774,6 +774,30 @@ func (user *User) Logout(state status.BridgeState, unpair bool) (logoutOK bool) return } +func conversationDataIsSus(portal *Portal, v *gmproto.Conversation) bool { + if !portal.IsPrivateChat() { + // Group chats hopefully never get bad updates + return false + } else if v.IsGroupChat { + // Group chat update for a DM is always sus + return true + } + count := 0 + mainName := "" + for _, pcp := range v.Participants { + if !pcp.IsMe { + if count == 0 { + mainName = pcp.FullName + count++ + } else if mainName != pcp.FullName { + count++ + } + } + } + // If there are multiple names in a DM, that's sus even if it's not marked as a group + return count > 1 +} + func (user *User) syncConversation(v *gmproto.Conversation, source string) { updateType := v.GetStatus() portal := user.GetPortalByID(v.GetConversationID()) @@ -807,8 +831,8 @@ func (user *User) syncConversation(v *gmproto.Conversation, source string) { if v.Participants == nil { log.Debug().Msg("Not syncing conversation with nil participants") return - } else if portal.IsPrivateChat() && v.IsGroupChat { - log.Warn().Msg("Ignoring group chat update for private chat") + } else if conversationDataIsSus(portal, v) { + log.Warn().Msg("Ignoring suspicious update for private chat") return } log.Debug().Msg("Syncing existing portal")