Only leave/kick if the redacted event is the current state event

This commit is contained in:
Till Faelligen 2023-07-12 14:48:44 +02:00
parent 92a633d0e4
commit 5a7d36d1b3
No known key found for this signature in database
GPG key ID: ACCDC9606D472758

View file

@ -526,8 +526,19 @@ func (r *Inputer) processRoomEvent(
// leavePseudoIDRoom leaves/kicks a user in the event of a membership event redaction. // leavePseudoIDRoom leaves/kicks a user in the event of a membership event redaction.
// TODO: This doesn't play well with users re-joining rooms, as in this case we have multiple join events with a mxid_mapping. // TODO: This doesn't play well with users re-joining rooms, as in this case we have multiple join events with a mxid_mapping.
func (r *Inputer) leavePseudoIDRoom(ctx context.Context, roomID spec.RoomID, originalRedactedEvent, redactionEvent gomatrixserverlib.PDU) error { func (r *Inputer) leavePseudoIDRoom(ctx context.Context, roomID spec.RoomID, originalRedactedEvent, redactionEvent gomatrixserverlib.PDU) error {
stateKey := originalRedactedEvent.StateKey()
currentStateEvent, err := r.DB.GetStateEvent(ctx, roomID.String(), originalRedactedEvent.Type(), *stateKey)
if err != nil {
return err
}
// If the redacted event is NOT the current state event, do nothing
if currentStateEvent.EventID() != originalRedactedEvent.EventID() {
return nil
}
var memberContent gomatrixserverlib.MemberContent var memberContent gomatrixserverlib.MemberContent
if err := json.Unmarshal(originalRedactedEvent.Content(), &memberContent); err != nil { if err = json.Unmarshal(originalRedactedEvent.Content(), &memberContent); err != nil {
return err return err
} }
if memberContent.Membership != spec.Join { if memberContent.Membership != spec.Join {
@ -549,9 +560,6 @@ func (r *Inputer) leavePseudoIDRoom(ctx context.Context, roomID spec.RoomID, ori
return nil return nil
} }
// check that the redacted event is the _current_ membership event
stateKey := originalRedactedEvent.StateKey()
signingIdentity, err := r.SigningIdentity(ctx, roomID, *userID) signingIdentity, err := r.SigningIdentity(ctx, roomID, *userID)
if err != nil { if err != nil {
return err return err