@@ -23,7 +23,19 @@ type pendingInvite struct {
23
23
Room id.RoomID
24
24
}
25
25
26
- func (pe * PolicyEvaluator ) HandleUserMayInvite (ctx context.Context , inviter , invitee id.UserID , roomID id.RoomID ) * mautrix.RespError {
26
+ func (pe * PolicyEvaluator ) HandleFederatedUserMayInvite (ctx context.Context , evt * event.Event ) * mautrix.RespError {
27
+ var roomCreator id.UserID
28
+ for _ , stateEvt := range evt .Unsigned .InviteRoomState {
29
+ switch stateEvt .Type {
30
+ case event .StateCreate :
31
+ roomCreator = stateEvt .Sender
32
+ }
33
+ // TODO also do things like checking room name
34
+ }
35
+ return pe .HandleUserMayInvite (ctx , evt .Sender , id .UserID (evt .GetStateKey ()), evt .RoomID , roomCreator )
36
+ }
37
+
38
+ func (pe * PolicyEvaluator ) HandleUserMayInvite (ctx context.Context , inviter , invitee id.UserID , roomID id.RoomID , roomCreator id.UserID ) * mautrix.RespError {
27
39
inviterServer := inviter .Homeserver ()
28
40
// We only care about federated invites.
29
41
if inviterServer == pe .Bot .ServerName && ! pe .FilterLocalInvites {
@@ -90,12 +102,18 @@ func (pe *PolicyEvaluator) HandleUserMayInvite(ctx context.Context, inviter, inv
90
102
// Parsing room IDs is generally not allowed, but in this case,
91
103
// if a room was created on a banned server, there's no reason to allow invites to it.
92
104
_ , _ , roomServer := id .ParseCommonIdentifier (roomID )
93
- if rec = pe .Store .MatchServer (lists , roomServer ).Recommendations ().BanOrUnban ; rec != nil && rec .Recommendation != event .PolicyRecommendationUnban {
94
- log .Debug ().
95
- Str ("policy_entity" , rec .EntityOrHash ()).
96
- Str ("policy_reason" , rec .Reason ).
97
- Msg ("Blocking invite to room on banned server" )
98
- return ptr .Ptr (mautrix .MForbidden .WithMessage ("Inviting users to this room is not allowed" ))
105
+ if roomServer == "" {
106
+ // If the room ID has no server part, check the create event sender (MSC4311).
107
+ roomServer = roomCreator .Homeserver ()
108
+ }
109
+ if roomServer != "" {
110
+ if rec = pe .Store .MatchServer (lists , roomServer ).Recommendations ().BanOrUnban ; rec != nil && rec .Recommendation != event .PolicyRecommendationUnban {
111
+ log .Debug ().
112
+ Str ("policy_entity" , rec .EntityOrHash ()).
113
+ Str ("policy_reason" , rec .Reason ).
114
+ Msg ("Blocking invite to room on banned server" )
115
+ return ptr .Ptr (mautrix .MForbidden .WithMessage ("Inviting users to this room is not allowed" ))
116
+ }
99
117
}
100
118
101
119
rec = nil
0 commit comments