Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Apply the federation_ip_range_blacklist to push and key revocation requests #8821

Merged
merged 16 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ acme:
# As of Synapse v1.4.0 this option also affects any outbound requests to identity
# servers provided by user input.
#
# As of Synapse v1.24.0 this option also affects any outbound requests to push
# servers provided by user input and to key revocation requests.
Copy link
Member

Choose a reason for hiding this comment

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

we should be clearer about what sort of "key" this is talking about. It might be clearer to say "for checking key validitity for third-party invite events".

#
# (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
# listed here, since they correspond to unroutable addresses.)
#
Expand Down
1 change: 0 additions & 1 deletion synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def __init__(self, hs):
super().__init__(hs)
self.hs = hs
self.is_mine_id = hs.is_mine_id
self.http_client = hs.get_simple_http_client()

self._presence_enabled = hs.config.use_presence

Expand Down
3 changes: 3 additions & 0 deletions synapse/config/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# As of Synapse v1.4.0 this option also affects any outbound requests to identity
# servers provided by user input.
#
# As of Synapse v1.24.0 this option also affects any outbound requests to push
# servers provided by user input and to key revocation requests.
#
# (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
# listed here, since they correspond to unroutable addresses.)
#
Expand Down
1 change: 0 additions & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ class FederationHandlerRegistry:

def __init__(self, hs: "HomeServer"):
self.config = hs.config
self.http_client = hs.get_simple_http_client()
self.clock = hs.get_clock()
self._instance_name = hs.get_instance_name()

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, hs: "HomeServer"):
self._message_handler = hs.get_message_handler()
self._server_notices_mxid = hs.config.server_notices_mxid
self.config = hs.config
self.http_client = hs.get_simple_http_client()
self.http_client = hs.get_proxied_blacklisted_http_client()
self._instance_name = hs.get_instance_name()
self._replication = hs.get_replication_data_handler()

Expand Down
8 changes: 3 additions & 5 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ class IdentityHandler(BaseHandler):
def __init__(self, hs):
super().__init__(hs)

# An HTTP client to contact trusted URLs.
self.http_client = SimpleHttpClient(hs)
# We create a blacklisting instance of SimpleHttpClient for contacting identity
# servers specified by clients
self.blacklisting_http_client = SimpleHttpClient(
hs, ip_blacklist=hs.config.federation_ip_range_blacklist
)
# An HTTP client for contacting identity servers specified by clients.
self.blacklisting_http_client = hs.get_proxied_blacklisted_http_client()
self.federation_http_client = hs.get_http_client()
self.hs = hs

Expand Down
2 changes: 1 addition & 1 deletion synapse/push/httppusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, hs, pusherdict):
if "url" not in self.data:
raise PusherConfigException("'url' required in data for HTTP pusher")
self.url = self.data["url"]
self.http_client = hs.get_proxied_http_client()
self.http_client = hs.get_proxied_blacklisted_http_client()
self.data_minus_url = {}
self.data_minus_url.update(self.data)
del self.data_minus_url["url"]
Expand Down
36 changes: 29 additions & 7 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,45 @@ def get_http_client_context_factory(self) -> IPolicyForHTTPS:

@cache_in_self
def get_simple_http_client(self) -> SimpleHttpClient:
"""
An HTTP client with no special configuration.
"""
return SimpleHttpClient(self)

@cache_in_self
def get_proxied_http_client(self) -> SimpleHttpClient:
"""
An HTTP client that uses configured HTTP(S) proxies.
"""
return SimpleHttpClient(
self,
http_proxy=os.getenvb(b"http_proxy"),
https_proxy=os.getenvb(b"HTTPS_PROXY"),
)

@cache_in_self
def get_proxied_blacklisted_http_client(self) -> SimpleHttpClient:
"""
An HTTP client that uses configured HTTP(S) proxies and blacklists IPs
based on the federation IP range blacklist.
"""
return SimpleHttpClient(
self,
ip_blacklist=self.config.federation_ip_range_blacklist,
http_proxy=os.getenvb(b"http_proxy"),
https_proxy=os.getenvb(b"HTTPS_PROXY"),
)

@cache_in_self
def get_http_client(self) -> MatrixFederationHttpClient:
"""
An HTTP client for federation.
"""
tls_client_options_factory = context_factory.FederationPolicyForHTTPS(
self.config
)
return MatrixFederationHttpClient(self, tls_client_options_factory)

@cache_in_self
def get_room_creation_handler(self) -> RoomCreationHandler:
return RoomCreationHandler(self)
Expand Down Expand Up @@ -515,13 +544,6 @@ def get_filtering(self) -> Filtering:
def get_pusherpool(self) -> PusherPool:
return PusherPool(self)

@cache_in_self
def get_http_client(self) -> MatrixFederationHttpClient:
tls_client_options_factory = context_factory.FederationPolicyForHTTPS(
self.config
)
return MatrixFederationHttpClient(self, tls_client_options_factory)

@cache_in_self
def get_media_repository_resource(self) -> MediaRepositoryResource:
# build the media repo resource. This indirects through the HomeServer
Expand Down
4 changes: 3 additions & 1 deletion tests/push/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def post_json_get_json(url, body):
config = self.default_config()
config["start_pushers"] = True

hs = self.setup_test_homeserver(config=config, proxied_http_client=m)
hs = self.setup_test_homeserver(
config=config, proxied_blacklisted_http_client=m
)

return hs

Expand Down
6 changes: 3 additions & 3 deletions tests/replication/test_pusher_shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_send_push_single_worker(self):
self.make_worker_hs(
"synapse.app.pusher",
{"start_pushers": True},
proxied_http_client=http_client_mock,
proxied_blacklisted_http_client=http_client_mock,
)

event_id = self._create_pusher_and_send_msg("user")
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_send_push_multiple_workers(self):
"worker_name": "pusher1",
"pusher_instances": ["pusher1", "pusher2"],
},
proxied_http_client=http_client_mock1,
proxied_blacklisted_http_client=http_client_mock1,
)

http_client_mock2 = Mock(spec_set=["post_json_get_json"])
Expand All @@ -148,7 +148,7 @@ def test_send_push_multiple_workers(self):
"worker_name": "pusher2",
"pusher_instances": ["pusher1", "pusher2"],
},
proxied_http_client=http_client_mock2,
proxied_blacklisted_http_client=http_client_mock2,
)

# We choose a user name that we know should go to pusher1.
Expand Down