Use SenderID Type (#3105)

This commit is contained in:
devonh 2023-06-07 17:14:35 +00:00 committed by GitHub
parent 7a1fd7f512
commit 8ea1a11105
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 502 additions and 275 deletions

View file

@ -140,22 +140,24 @@ func ExchangeThirdPartyInvite(
}
}
_, senderDomain, err := cfg.Matrix.SplitLocalID('@', proto.Sender)
if err != nil {
userID, err := rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, spec.SenderID(proto.SenderID))
if err != nil || userID == nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: spec.BadJSON("Invalid sender ID: " + err.Error()),
JSON: spec.BadJSON("Invalid sender ID"),
}
}
senderDomain := userID.Domain()
// Check that the state key is correct.
_, targetDomain, err := gomatrixserverlib.SplitID('@', *proto.StateKey)
if err != nil {
targetUserID, err := rsAPI.QueryUserIDForSender(httpReq.Context(), roomID, spec.SenderID(*proto.StateKey))
if err != nil || targetUserID == nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: spec.BadJSON("The event's state key isn't a Matrix user ID"),
}
}
targetDomain := targetUserID.Domain()
// Check that the target user is from the requesting homeserver.
if targetDomain != request.Origin() {
@ -271,7 +273,7 @@ func createInviteFrom3PIDInvite(
// Build the event
proto := &gomatrixserverlib.ProtoEvent{
Type: "m.room.member",
Sender: inv.Sender,
SenderID: inv.Sender,
RoomID: inv.RoomID,
StateKey: &inv.MXID,
}