From f21a5856471bdbdd24f976033ba9796db25fa5b9 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 9 Nov 2021 15:55:53 +0000 Subject: [PATCH] Error on obvious problems with the make_join response instead of overwriting them --- federationsender/internal/perform.go | 29 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/federationsender/internal/perform.go b/federationsender/internal/perform.go index 3623577f..2c9e186e 100644 --- a/federationsender/internal/perform.go +++ b/federationsender/internal/perform.go @@ -162,21 +162,28 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer( // Set all the fields to be what they should be, this should be a no-op // but it's possible that the remote server returned us something "odd" - respMakeJoin.JoinEvent.Type = gomatrixserverlib.MRoomMember - respMakeJoin.JoinEvent.Sender = userID - respMakeJoin.JoinEvent.StateKey = &userID - respMakeJoin.JoinEvent.RoomID = roomID - respMakeJoin.JoinEvent.Redacts = "" - if content == nil { - content = map[string]interface{}{} + switch { + case respMakeJoin.JoinEvent.Type != gomatrixserverlib.MRoomMember: + fallthrough + case respMakeJoin.JoinEvent.Sender != userID: + fallthrough + case respMakeJoin.JoinEvent.StateKey == nil: + fallthrough + case *respMakeJoin.JoinEvent.StateKey != userID: + fallthrough + case respMakeJoin.JoinEvent.RoomID != roomID: + fallthrough + case respMakeJoin.JoinEvent.Redacts != "": + fallthrough + case len(respMakeJoin.JoinEvent.Content) == 0: + return fmt.Errorf("respMakeJoin.JoinEvent contains invalid values") + } + if err = json.Unmarshal(respMakeJoin.JoinEvent.Content, &content); err != nil { + return fmt.Errorf("json.Unmarshal: %w", err) } - content["membership"] = "join" if err = respMakeJoin.JoinEvent.SetContent(content); err != nil { return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err) } - if err = respMakeJoin.JoinEvent.SetUnsigned(struct{}{}); err != nil { - return fmt.Errorf("respMakeJoin.JoinEvent.SetUnsigned: %w", err) - } // Work out if we support the room version that has been supplied in // the make_join response.