Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options to drop invites matching certain criteria #530

Merged
merged 4 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/530.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `email.third_party_invite_homeserver_blocklist` and `email.third_party_invite_room_blocklist` config options to block invites from a list of homeservers or for a list of rooms.
17 changes: 17 additions & 0 deletions sydent/config/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ def parse_config(self, cfg: ConfigParser) -> bool:
"email", "email.third_party_invite_domain_obfuscate_characters"
)

third_party_invite_homeserver_blocklist = cfg.get(
"email", "email.third_party_invite_homeserver_blocklist", fallback=""
)
third_party_invite_room_blocklist = cfg.get(
"email", "email.third_party_invite_room_blocklist", fallback=""
)
self.third_party_invite_homeserver_blocklist = {
server
for server in third_party_invite_homeserver_blocklist.split("\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we insert newlines in the config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, like so:

some_section.some_list_option =
        item1
        item2

I started with comma separated strings, but that looked unwieldy with long lists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

if server # filter out empty lines
}
self.third_party_invite_room_blocklist = {
room_id
for room_id in third_party_invite_room_blocklist.split("\n")
if room_id # filter out empty lines
}

self.email_sender_ratelimit_burst = cfg.getint(
"email", "email.ratelimit_sender.burst", fallback=5
)
Expand Down
8 changes: 8 additions & 0 deletions sydent/http/servlets/store_invite_servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ def render_POST(self, request: Request) -> JsonDict:
"Store invite request from %s to %s, in %s", sender, address, roomId
)

sender_homeserver = sender.split(":", 1)[1]
if (
roomId in self.sydent.config.email.third_party_invite_room_blocklist
or sender_homeserver
in self.sydent.config.email.third_party_invite_homeserver_blocklist
):
raise MatrixRestError(403, "M_UNAUTHORIZED", "Invite not allowed")

globalAssocStore = GlobalAssociationStore(self.sydent)
mxid = globalAssocStore.getMxid(medium, normalised_address)
if mxid:
Expand Down