Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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/5093.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add optional whitelist to public rooms directory over federation.
11 changes: 11 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ pid_file: DATADIR/homeserver.pid
# - nyc.example.com
# - syd.example.com

# Restricts access to the server's public rooms directory over
# federation to a whitelist of homeservers. If this is set to an empty
# array ('[]'), forbids any homeserver to fetch the server's public
# rooms directory. If not specified, the default is to whitelist
# everything.
#
#public_rooms_over_federation_whitelist:
# - lon.example.com
# - nyc.example.com
# - syd.example.com

# List of ports that Synapse should listen on, their purpose and their
# configuration.
#
Expand Down
21 changes: 21 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ def read_config(self, config):
for domain in federation_domain_whitelist:
self.federation_domain_whitelist[domain] = True

self.public_rooms_over_federation_whitelist = None
public_rooms_over_federation_whitelist = config.get(
"public_rooms_over_federation_whitelist", None
)
# turn the whitelist into a hash for speed of lookup
if public_rooms_over_federation_whitelist is not None:
self.public_rooms_over_federation_whitelist = {}
for domain in public_rooms_over_federation_whitelist:
self.public_rooms_over_federation_whitelist[domain] = True

if self.public_baseurl is not None:
if self.public_baseurl[-1] != '/':
self.public_baseurl += '/'
Expand Down Expand Up @@ -351,6 +361,17 @@ def default_config(self, server_name, data_dir_path, **kwargs):
# - nyc.example.com
# - syd.example.com

# Restricts access to the server's public rooms directory over
# federation to a whitelist of homeservers. If this is set to an empty
# array ('[]'), forbids any homeserver to fetch the server's public
# rooms directory. If not specified, the default is to whitelist
# everything.
#
#public_rooms_over_federation_whitelist:
# - lon.example.com
# - nyc.example.com
# - syd.example.com

# List of ports that Synapse should listen on, their purpose and their
# configuration.
#
Expand Down
10 changes: 10 additions & 0 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(self, hs):
self.server_name = hs.hostname
self.store = hs.get_datastore()
self.federation_domain_whitelist = hs.config.federation_domain_whitelist
self.public_rooms_whitelist = hs.config.public_rooms_over_federation_whitelist

# A method just so we can pass 'self' as the authenticator to the Servlets
@defer.inlineCallbacks
Expand Down Expand Up @@ -133,6 +134,15 @@ def authenticate_request(self, request, content):
):
raise FederationDeniedError(origin)

# Special case the public rooms directory since it has another dedicated
# whitelist.
if (
"publicRooms" in request.path and
self.public_rooms_whitelist is not None and
origin not in self.public_rooms_whitelist
):
raise FederationDeniedError(origin)

if not json_request["signatures"]:
raise NoAuthenticationError(
401, "Missing Authorization headers", Codes.UNAUTHORIZED,
Expand Down