Only auto-join rooms when invited by allowed users
Previously, anyone (even across federation) could invite you to a room and the bot would join. It may not have provided a useful purpose, but it still joined all rooms it was invited to. We now only join rooms when we're invited by a person who is actually allowed to use the bot. Fixes https://gitlab.com/etke.cc/postmoogle/-/issues/17
This commit is contained in:
14
bot/sync.go
14
bot/sync.go
@@ -5,9 +5,13 @@ import (
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/event"
|
||||
|
||||
"gitlab.com/etke.cc/postmoogle/utils"
|
||||
)
|
||||
|
||||
func (b *Bot) initSync() {
|
||||
b.lp.SetJoinPermit(b.joinPermit)
|
||||
|
||||
b.lp.OnEventType(
|
||||
event.StateMember,
|
||||
func(_ mautrix.EventSource, evt *event.Event) {
|
||||
@@ -26,6 +30,16 @@ func (b *Bot) initSync() {
|
||||
})
|
||||
}
|
||||
|
||||
// joinPermit is called by linkpearl when processing "invite" events and deciding if rooms should be auto-joined or not
|
||||
func (b *Bot) joinPermit(evt *event.Event) bool {
|
||||
if !utils.Match(evt.Sender.String(), b.allowedUsers) {
|
||||
b.log.Debug("Rejecting room invitation from unallowed user: %s", evt.Sender)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *Bot) onMembership(evt *event.Event) {
|
||||
ctx := newContext(evt)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user