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

Commit a1b62af

Browse files
authored
Validate federation destinations and log an error if server name is invalid. (#13318)
1 parent d399504 commit a1b62af

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

changelog.d/13318.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Validate federation destinations and log an error if a destination is invalid.

synapse/http/matrixfederationclient.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
from synapse.util import json_decoder
8080
from synapse.util.async_helpers import AwakenableSleeper, timeout_deferred
8181
from synapse.util.metrics import Measure
82+
from synapse.util.stringutils import parse_and_validate_server_name
8283

8384
if 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:

tests/federation/test_federation_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
)

0 commit comments

Comments
 (0)