This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1+ Validate federation destinations and log an error if a destination is invalid.
Original file line number Diff line number Diff line change 7979from synapse .util import json_decoder
8080from synapse .util .async_helpers import AwakenableSleeper , timeout_deferred
8181from synapse .util .metrics import Measure
82+ from synapse .util .stringutils import parse_and_validate_server_name
8283
8384if TYPE_CHECKING :
8485 from synapse .server import HomeServer
@@ -479,6 +480,14 @@ async def _send_request(
479480 RequestSendFailed: If there were problems connecting to the
480481 remote, due to e.g. DNS failures, connection timeouts etc.
481482 """
483+ # Validate server name and log if it is an invalid destination, this is
484+ # partially to help track down code paths where we haven't validated before here
485+ try :
486+ parse_and_validate_server_name (request .destination )
487+ except ValueError :
488+ logger .exception (f"Invalid destination: { request .destination } ." )
489+ raise FederationDeniedError (request .destination )
490+
482491 if timeout :
483492 _sec_timeout = timeout / 1000
484493 else :
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ def test_get_room_state(self):
102102 # now fire off the request
103103 state_resp , auth_resp = self .get_success (
104104 self .hs .get_federation_client ().get_room_state (
105- "yet_another_server " ,
105+ "yet.another.server " ,
106106 test_room_id ,
107107 "event_id" ,
108108 RoomVersions .V9 ,
@@ -112,7 +112,7 @@ def test_get_room_state(self):
112112 # check the right call got made to the agent
113113 self ._mock_agent .request .assert_called_once_with (
114114 b"GET" ,
115- b"matrix://yet_another_server /_matrix/federation/v1/state/%21room_id?event_id=event_id" ,
115+ b"matrix://yet.another.server /_matrix/federation/v1/state/%21room_id?event_id=event_id" ,
116116 headers = mock .ANY ,
117117 bodyProducer = None ,
118118 )
You can’t perform that action at this time.
0 commit comments