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
Add federation_domain_whitelist option #2820
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f79378
make replication tests pass on OSX
ara4n 4b090cb
add federation_domain_whitelist
ara4n 313a489
incorporate PR feedback
ara4n b424c16
fix tests
ara4n c776c52
Back out unrelated changes
richvdh fa80b49
fix thinko
ara4n 3869981
remove unreachable except block
ara4n 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 |
---|---|---|
|
@@ -55,14 +55,16 @@ def read_config(self, config): | |
"block_non_admin_invites", False, | ||
) | ||
|
||
# FIXME: federation_domain_whitelist needs sytests | ||
self.federation_domain_whitelist = None | ||
federation_domain_whitelist = config.get( | ||
"federation_domain_whitelist", [] | ||
"federation_domain_whitelist", None | ||
) | ||
# turn the whitelist into a hash for speed of lookup | ||
self.federation_domain_whitelist = {} | ||
for domain in federation_domain_whitelist: | ||
self.federation_domain_whitelist[domain] = True | ||
# FIXME: federation_domain_whitelist needs sytests | ||
if federation_domain_whitelist is not None: | ||
self.federation_domain_whitelist = {} | ||
for domain in federation_domain_whitelist: | ||
self.federation_domain_whitelist[domain] = True | ||
|
||
if self.public_baseurl is not None: | ||
if self.public_baseurl[-1] != '/': | ||
|
@@ -222,7 +224,8 @@ def default_config(self, server_name, **kwargs): | |
# Restrict federation to the following whitelist of domains. | ||
# N.B. we recommend also firewalling your federation listener to limit | ||
# inbound federation traffic as early as possible, rather than relying | ||
# purely on this application-layer restriction. | ||
# purely on this application-layer restriction. If not specified, the | ||
# default is to whitelist nothing. | ||
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. s/nothing/everything? |
||
# | ||
# federation_domain_whitelist: | ||
# - lon.example.com | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,7 +226,7 @@ def get_remote_media(self, request, server_name, media_id, name): | |
to request | ||
""" | ||
if ( | ||
self.federation_domain_whitelist and | ||
self.federation_domain_whitelist is not None and | ||
server_name not in self.federation_domain_whitelist | ||
): | ||
raise FederationDeniedError(server_name) | ||
|
@@ -266,7 +266,7 @@ def get_remote_media_info(self, server_name, media_id): | |
Deferred[dict]: The media_info of the file | ||
""" | ||
if ( | ||
self.federation_domain_whitelist and | ||
self.federation_domain_whitelist is not None and | ||
server_name not in self.federation_domain_whitelist | ||
): | ||
raise FederationDeniedError(server_name) | ||
|
@@ -387,8 +387,8 @@ def _download_remote_file(self, server_name, media_id, file_id): | |
logger.warn("Not retrying destination %r", server_name) | ||
raise SynapseError(502, "Failed to fetch remote media") | ||
except FederationDeniedError as e: | ||
logger.debug(e) | ||
raise SynapseError(403, e.message) | ||
logger.info(e) | ||
raise e | ||
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. this should probably be Although, looking at it, I don't think you'll ever get here, because |
||
except Exception: | ||
logger.exception("Failed to fetch remote media %s/%s", | ||
server_name, media_id) | ||
|
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.
It feels very odd that you can whitelist everything by having an empty whitelist. I wonder if it would be better to make an empty whitelist actually mean that nothing is allowed, and have the default be
*
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.
good point; fixed.