From d6e95ccb9e03d8a03cb185e6e7a6846e726c2555 Mon Sep 17 00:00:00 2001 From: David Florness Date: Sun, 23 May 2021 10:28:03 -0400 Subject: [PATCH] Start and join events for keys msgs must belong to the same election --- election/msg.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/election/msg.go b/election/msg.go index fee54e0..ccf800c 100644 --- a/election/msg.go +++ b/election/msg.go @@ -415,26 +415,36 @@ func (elections *ElectionsMap) onKeysMessage(evt *event.Event, client *mautrix.C return } + // this makes JoinIDIndex availabe below + startEvt := elections.EventStore.GetStartEvent(evt.RoomID, content.StartID) + if startEvt == nil { + debugf("we couldn't process the start event, %s", content.StartID) + return + } + + el := elections.GetElection(startEvt.CreateID) + if el == nil { + // should never happen because we retrieved the join event above + errorf("election %s doesn't exist", startEvt.ID) + return + } + joinEvt := elections.EventStore.GetJoinEvent(evt.RoomID, content.JoinID) if joinEvt == nil { debugf("we couldn't get the join event, %s", content.JoinID) return } + + // ensure keys sender also sent join event if evt.Sender != joinEvt.Sender { warnf("they did not send the join event; %s did", joinEvt.Sender) return } - // process the start event so that JoinIDIndex is availabe below - if elections.EventStore.GetStartEvent(evt.RoomID, content.StartID) == nil { - debugf("we couldn't process the start event, %s", content.StartID) - return - } - - el := elections.GetElection(joinEvt.CreateID) - if el == nil { - // should never happen because we retrieved the join event above - errorf("election %s doesn't exist", joinEvt.ID) + // ensure join event and start event belong to the same election + if _, voterExists := el.Joins[joinEvt.ID]; !voterExists { + warnf("the join event %s and start event %s do not belong to the same election", + joinEvt.ID, startEvt.ID) return } -- 2.38.4