This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix bug where preserved threepid user comes to sign up and server is … #3777
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ea068d6
fix bug where preserved threepid user comes to sign up and server is …
neilisfragile 3d6aa06
news fragemnt
neilisfragile 09f3cf1
ensure post registration auth checks do not fail erroneously
neilisfragile a796bdd
typo
neilisfragile e8e5406
fix reference to is_threepid_reserved
neilisfragile 0b01281
move threepid checker to config, add missing yields
neilisfragile 301cb60
assert rather than warn
neilisfragile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix bug where preserved threepid user comes to sign up and server is mau blocked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
from synapse import event_auth | ||
from synapse.api.constants import EventTypes, JoinRules, Membership | ||
from synapse.api.errors import AuthError, Codes, ResourceLimitError | ||
from synapse.config.server import is_threepid_reserved | ||
from synapse.types import UserID | ||
from synapse.util.caches import CACHE_SIZE_FACTOR, register_cache | ||
from synapse.util.caches.lrucache import LruCache | ||
|
@@ -775,13 +776,18 @@ def check_in_room_or_world_readable(self, room_id, user_id): | |
) | ||
|
||
@defer.inlineCallbacks | ||
def check_auth_blocking(self, user_id=None): | ||
def check_auth_blocking(self, user_id=None, threepid=None): | ||
"""Checks if the user should be rejected for some external reason, | ||
such as monthly active user limiting or global disable flag | ||
|
||
Args: | ||
user_id(str|None): If present, checks for presence against existing | ||
MAU cohort | ||
threepid(dict|None): If present, checks for presence against configured | ||
reserved threepid. Used in cases where the user is trying register | ||
with a MAU blocked server, normally they would be rejected but their | ||
threepid is on the reserved list. user_id and | ||
threepid should never be set at the same time. | ||
""" | ||
|
||
# Never fail an auth check for the server notices users | ||
|
@@ -797,6 +803,10 @@ def check_auth_blocking(self, user_id=None): | |
limit_type=self.hs.config.hs_disabled_limit_type | ||
) | ||
if self.hs.config.limit_usage_by_mau is True: | ||
|
||
if user_id and threepid: | ||
logger.warn("Called with both user_id and threepid, this shoudn't happen") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I'd |
||
|
||
# If the user is already part of the MAU cohort or a trial user | ||
if user_id: | ||
timestamp = yield self.store.user_last_seen_monthly_active(user_id) | ||
|
@@ -806,12 +816,16 @@ def check_auth_blocking(self, user_id=None): | |
is_trial = yield self.store.is_trial_user(user_id) | ||
if is_trial: | ||
return | ||
elif threepid: | ||
# If the user does not exist yet, but is signing up with a | ||
# reserved threepid then pass auth check | ||
if is_threepid_reserved(self.hs.config, threepid): | ||
return | ||
# Else if there is no room in the MAU bucket, bail | ||
current_mau = yield self.store.get_monthly_active_count() | ||
if current_mau >= self.hs.config.max_mau_value: | ||
raise ResourceLimitError( | ||
403, "Monthly Active User Limit Exceeded", | ||
|
||
admin_contact=self.hs.config.admin_contact, | ||
errcode=Codes.RESOURCE_LIMIT_EXCEEDED, | ||
limit_type="monthly_active_user" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please doc threepid arg