From ac4d0072cf5507d7de1504d16aa5c4ca8537eb26 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 25 May 2022 14:31:07 +0100 Subject: [PATCH] Fix using the remote provided event from `/send_join` (#2490) --- federationapi/internal/perform.go | 12 ++++++++---- federationapi/routing/join.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/federationapi/internal/perform.go b/federationapi/internal/perform.go index 970a64653..9100c8f18 100644 --- a/federationapi/internal/perform.go +++ b/federationapi/internal/perform.go @@ -213,10 +213,14 @@ func (r *FederationInternalAPI) performJoinUsingServer( // If the remote server returned an event in the "event" key of // the send_join request then we should use that instead. It may // contain signatures that we don't know about. - if respSendJoin.Event != nil && isWellFormedMembershipEvent( - respSendJoin.Event, roomID, userID, r.cfg.Matrix.ServerName, - ) { - event = respSendJoin.Event + if len(respSendJoin.Event) > 0 { + var remoteEvent *gomatrixserverlib.Event + remoteEvent, err = respSendJoin.Event.UntrustedEvent(respMakeJoin.RoomVersion) + if err == nil && isWellFormedMembershipEvent( + remoteEvent, roomID, userID, r.cfg.Matrix.ServerName, + ) { + event = remoteEvent + } } // Sanity-check the join response to ensure that it has a create diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index 9f8d94105..abf9c0945 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -403,7 +403,7 @@ func SendJoin( StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents), AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents), Origin: cfg.Matrix.ServerName, - Event: &signed, + Event: signed.JSON(), }, } } diff --git a/go.mod b/go.mod index 89ff04f63..2513ac87f 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 - github.com/matrix-org/gomatrixserverlib v0.0.0-20220524100759-f98e737f8f9c + github.com/matrix-org/gomatrixserverlib v0.0.0-20220525125811-a75fa15a03a0 github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48 github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4 github.com/mattn/go-sqlite3 v1.14.10 diff --git a/go.sum b/go.sum index 3ffd52182..03e71d4a5 100644 --- a/go.sum +++ b/go.sum @@ -795,8 +795,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4= github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20220524100759-f98e737f8f9c h1:J9krMtVgo4mV/G+mRA1u3GL6nNxdNnuPcs891uIQGic= -github.com/matrix-org/gomatrixserverlib v0.0.0-20220524100759-f98e737f8f9c/go.mod h1:V5eO8rn/C3rcxig37A/BCeKerLFS+9Avg/77FIeTZ48= +github.com/matrix-org/gomatrixserverlib v0.0.0-20220525125811-a75fa15a03a0 h1:wmxJJA5dczakTi7UsU/MWuWJY3gmC6RWzTN2S484tHo= +github.com/matrix-org/gomatrixserverlib v0.0.0-20220525125811-a75fa15a03a0/go.mod h1:V5eO8rn/C3rcxig37A/BCeKerLFS+9Avg/77FIeTZ48= github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48 h1:W0sjjC6yjskHX4mb0nk3p0fXAlbU5bAFUFeEtlrPASE= github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48/go.mod h1:ulJzsVOTssIVp1j/m5eI//4VpAGDkMt5NrRuAVX7wpc= github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7/go.mod h1:vVQlW/emklohkZnOPwD3LrZUBqdfsbiyO3p1lNV8F6U=