From b1605cdd23a37701c55906c9118e43b4d32ceb7f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 24 Jul 2019 22:44:39 +0100 Subject: [PATCH 1/7] log when a redaction attempts to redact an event in a different room --- changelog.d/5767.bugfix | 1 + synapse/storage/events_worker.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 changelog.d/5767.bugfix diff --git a/changelog.d/5767.bugfix b/changelog.d/5767.bugfix new file mode 100644 index 000000000000..1a76d02e3214 --- /dev/null +++ b/changelog.d/5767.bugfix @@ -0,0 +1 @@ +Log when a redaction attempts to redact an event in a different room. diff --git a/synapse/storage/events_worker.py b/synapse/storage/events_worker.py index 858fc755a121..7dbb5df09a34 100644 --- a/synapse/storage/events_worker.py +++ b/synapse/storage/events_worker.py @@ -268,6 +268,14 @@ def get_events_as_list( ) continue + if original_event.room_id != entry.event.room_id: + logger.info( + "Withholding redaction %s of event %s from a different room", + event_id, + redacted_event_id, + ) + continue + if entry.event.internal_metadata.need_to_check_redaction(): original_domain = get_domain_from_id(original_event.sender) redaction_domain = get_domain_from_id(entry.event.sender) @@ -636,9 +644,21 @@ def _maybe_redact_event_row(self, original_ev, redactions): if not redaction_entry: # we don't have the redaction event, or the redaction event was not # authorized. + logger.debug( + "%s was redacted by %s but redaction not found/authed", + original_ev.event_id, + redaction_id, + ) continue redaction_event = redaction_entry.event + if redaction_event.room_id != original_ev.room_id: + logger.debug( + "%s was redacted by %s but redaction was in a different room!", + original_ev.event_id, + redaction_id, + ) + continue # Starting in room version v3, some redactions need to be # rechecked if we didn't have the redacted event at the @@ -650,8 +670,15 @@ def _maybe_redact_event_row(self, original_ev, redactions): redaction_event.internal_metadata.recheck_redaction = False else: # Senders don't match, so the event isn't actually redacted + logger.debug( + "%s was redacted by %s but the senders don't match", + original_ev.event_id, + redaction_id, + ) continue + logger.debug("Redacting %s due to %s", original_ev.event_id, redaction_id) + # we found a good redaction event. Redact! redacted_event = prune_event(original_ev) redacted_event.unsigned["redacted_by"] = redaction_id From 0f2ecb961e580d5d039360edf041720680f8ad8c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 26 Jul 2019 06:36:48 +0000 Subject: [PATCH 2/7] Fix DoS when there is a cycle in redaction events Make sure that synapse doesn't explode when a redaction redacts itself, or there is a larger cycle. --- synapse/storage/events_worker.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/synapse/storage/events_worker.py b/synapse/storage/events_worker.py index 7dbb5df09a34..06379281b63a 100644 --- a/synapse/storage/events_worker.py +++ b/synapse/storage/events_worker.py @@ -637,6 +637,10 @@ def _maybe_redact_event_row(self, original_ev, redactions): # we choose to ignore redactions of m.room.create events. return None + if original_ev.type == "m.room.redaction": + # ... and redaction events + return None + redaction_map = yield self._get_events_from_cache_or_db(redactions) for redaction_id in redactions: From 1f8bae7724713a36b7602fde439f316f1ff5b8cf Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 23 Jul 2019 13:31:03 +0100 Subject: [PATCH 3/7] Log when we receive receipt from a different origin --- synapse/handlers/receipts.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/synapse/handlers/receipts.py b/synapse/handlers/receipts.py index a85dd8cdee69..e58bf7e360bf 100644 --- a/synapse/handlers/receipts.py +++ b/synapse/handlers/receipts.py @@ -17,7 +17,7 @@ from twisted.internet import defer from synapse.handlers._base import BaseHandler -from synapse.types import ReadReceipt +from synapse.types import ReadReceipt, get_domain_from_id logger = logging.getLogger(__name__) @@ -40,18 +40,27 @@ def __init__(self, hs): def _received_remote_receipt(self, origin, content): """Called when we receive an EDU of type m.receipt from a remote HS. """ - receipts = [ - ReadReceipt( - room_id=room_id, - receipt_type=receipt_type, - user_id=user_id, - event_ids=user_values["event_ids"], - data=user_values.get("data", {}), - ) - for room_id, room_values in content.items() - for receipt_type, users in room_values.items() - for user_id, user_values in users.items() - ] + receipts = [] + for room_id, room_values in content.items(): + for receipt_type, users in room_values.items(): + for user_id, user_values in users.items(): + if get_domain_from_id(user_id) != origin: + logger.info( + "Received receipt for user %r from server %s, ignoring", + user_id, + origin, + ) + continue + + receipts.append( + ReadReceipt( + room_id=room_id, + receipt_type=receipt_type, + user_id=user_id, + event_ids=user_values["event_ids"], + data=user_values.get("data", {}), + ) + ) yield self._handle_new_receipts(receipts) From d1020653fcbecabcf8e109dafc6258b1f2c2afd0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 26 Jul 2019 10:08:22 +0100 Subject: [PATCH 4/7] Log when we receive a /make_* request from a different origin --- changelog.d/5744.bugfix | 1 + synapse/federation/federation_server.py | 4 +-- synapse/handlers/federation.py | 37 +++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 changelog.d/5744.bugfix diff --git a/changelog.d/5744.bugfix b/changelog.d/5744.bugfix new file mode 100644 index 000000000000..7b67ebb2d3e4 --- /dev/null +++ b/changelog.d/5744.bugfix @@ -0,0 +1 @@ +Log when we receive a `/make_*` request from a different origin. diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 8c0a18b12039..ed2b6d5eef06 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -369,7 +369,7 @@ def on_make_join_request(self, origin, room_id, user_id, supported_versions): logger.warn("Room version %s not in %s", room_version, supported_versions) raise IncompatibleRoomVersionError(room_version=room_version) - pdu = yield self.handler.on_make_join_request(room_id, user_id) + pdu = yield self.handler.on_make_join_request(origin, room_id, user_id) time_now = self._clock.time_msec() defer.returnValue( {"event": pdu.get_pdu_json(time_now), "room_version": room_version} @@ -423,7 +423,7 @@ def on_send_join_request(self, origin, content, room_id): def on_make_leave_request(self, origin, room_id, user_id): origin_host, _ = parse_server_name(origin) yield self.check_server_matches_acl(origin_host, room_id) - pdu = yield self.handler.on_make_leave_request(room_id, user_id) + pdu = yield self.handler.on_make_leave_request(origin, room_id, user_id) room_version = yield self.store.get_room_version(room_id) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 57be968c67c8..30b69af82c7f 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -1204,11 +1204,28 @@ def _handle_queued_pdus(self, room_queue): @defer.inlineCallbacks @log_function - def on_make_join_request(self, room_id, user_id): + def on_make_join_request(self, origin, room_id, user_id): """ We've received a /make_join/ request, so we create a partial join event for the room and return that. We do *not* persist or process it until the other server has signed it and sent it back. + + Args: + origin (str): The (verified) server name of the requesting server. + room_id (str): Room to create join event in + user_id (str): The user to create the join for + + Returns: + Deferred[FrozenEvent] """ + + if get_domain_from_id(user_id) != origin: + logger.info( + "Got /make_join request for user %r from different origin %s, ignoring", + user_id, + origin, + ) + raise SynapseError(403, "User not from origin", Codes.FORBIDDEN) + event_content = {"membership": Membership.JOIN} room_version = yield self.store.get_room_version(room_id) @@ -1411,11 +1428,27 @@ def _make_and_verify_event( @defer.inlineCallbacks @log_function - def on_make_leave_request(self, room_id, user_id): + def on_make_leave_request(self, origin, room_id, user_id): """ We've received a /make_leave/ request, so we create a partial leave event for the room and return that. We do *not* persist or process it until the other server has signed it and sent it back. + + Args: + origin (str): The (verified) server name of the requesting server. + room_id (str): Room to create leave event in + user_id (str): The user to create the leave for + + Returns: + Deferred[FrozenEvent] """ + if get_domain_from_id(user_id) != origin: + logger.info( + "Got /make_leave request for user %r from different origin %s, ignoring", + user_id, + origin, + ) + raise SynapseError(403, "User not from origin", Codes.FORBIDDEN) + room_version = yield self.store.get_room_version(room_id) builder = self.event_builder_factory.new( room_version, From dde6ea7ff6b18bb1da697a365326f34ea33baf88 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 26 Jul 2019 11:33:16 +0100 Subject: [PATCH 5/7] 1.2.1 --- CHANGES.md | 24 +++++++++++++++++++++++- changelog.d/5744.bugfix | 1 - changelog.d/5767.bugfix | 1 - debian/changelog | 6 ++++++ synapse/__init__.py | 2 +- 5 files changed, 30 insertions(+), 4 deletions(-) delete mode 100644 changelog.d/5744.bugfix delete mode 100644 changelog.d/5767.bugfix diff --git a/CHANGES.md b/CHANGES.md index d655723326f7..ec7927953950 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,18 @@ +Synapse 1.2.1 (2019-07-26) +========================== + +Security update +--------------- + +This release includes *four* security fixes: + +- Prevent an attack where a federated server could send redactions for arbitrary events in v1 and v2 rooms. ([\#5767](https://github.com/matrix-org/synapse/issues/5767)) +- Prevent a denial-of-service attack where cycles of redaction events would make Synapse spin infinitely. Thanks to `@lrizika:matrix.org` for identifying and responsibly disclosing this issue. ([0f2ecb961](https://github.com/matrix-org/synapse/commit/0f2ecb961)) +- Prevent an attack where users could be joined or parted from public rooms without their consent. Thanks to @Dylanger for identifying and responsibly disclosing this issue. ([\#5744](https://github.com/matrix-org/synapse/issues/5744)) +- Fix a vulnerability where a federated server could spoof read-receipts from users on other servers. ([\#5743](https://github.com/matrix-org/synapse/issues/5743)) + +Note that Synapse 1.2.0 also contained a security fix which was not correctly identified during the original release. The changelog below is now updated. + Synapse 1.2.0 (2019-07-25) ========================== @@ -16,6 +31,14 @@ Bugfixes Synapse 1.2.0rc1 (2019-07-22) ============================= +Security fixes +-------------- + +This update included a security fix which was initially incorrectly flagged as +a regular bug fix. + +- It was possible for a room moderator to send a redaction for an `m.room.create` event, which would downgrade the room to version 1. Thanks to `/dev/ponies` for identifying and responsibly disclosing this issue! ([\#5701](https://github.com/matrix-org/synapse/issues/5701)) + Features -------- @@ -41,7 +64,6 @@ Bugfixes - Fix bug in #5626 that prevented the original_event field from actually having the contents of the original event in a call to `/relations`. ([\#5654](https://github.com/matrix-org/synapse/issues/5654)) - Fix 3PID bind requests being sent to identity servers as `application/x-form-www-urlencoded` data, which is deprecated. ([\#5658](https://github.com/matrix-org/synapse/issues/5658)) - Fix some problems with authenticating redactions in recent room versions. ([\#5699](https://github.com/matrix-org/synapse/issues/5699), [\#5700](https://github.com/matrix-org/synapse/issues/5700), [\#5707](https://github.com/matrix-org/synapse/issues/5707)) -- Ignore redactions of m.room.create events. ([\#5701](https://github.com/matrix-org/synapse/issues/5701)) Updates to the Docker image diff --git a/changelog.d/5744.bugfix b/changelog.d/5744.bugfix deleted file mode 100644 index 7b67ebb2d3e4..000000000000 --- a/changelog.d/5744.bugfix +++ /dev/null @@ -1 +0,0 @@ -Log when we receive a `/make_*` request from a different origin. diff --git a/changelog.d/5767.bugfix b/changelog.d/5767.bugfix deleted file mode 100644 index 1a76d02e3214..000000000000 --- a/changelog.d/5767.bugfix +++ /dev/null @@ -1 +0,0 @@ -Log when a redaction attempts to redact an event in a different room. diff --git a/debian/changelog b/debian/changelog index aafdd1cde205..6634c1085a6b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +matrix-synapse-py3 (1.2.1) stable; urgency=medium + + * New synapse release 1.2.1. + + -- Synapse Packaging team Fri, 26 Jul 2019 11:32:47 +0100 + matrix-synapse-py3 (1.2.0) stable; urgency=medium [ Amber Brown ] diff --git a/synapse/__init__.py b/synapse/__init__.py index 3435de4e2f12..8301a13d8f92 100644 --- a/synapse/__init__.py +++ b/synapse/__init__.py @@ -35,4 +35,4 @@ except ImportError: pass -__version__ = "1.2.0" +__version__ = "1.2.1" From 8b16696b24a9cf22b3583c4dca733c0db527b4a0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 26 Jul 2019 11:36:28 +0100 Subject: [PATCH 6/7] correct attributions in changelog --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ec7927953950..2814d9586aa3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,7 +9,8 @@ This release includes *four* security fixes: - Prevent an attack where a federated server could send redactions for arbitrary events in v1 and v2 rooms. ([\#5767](https://github.com/matrix-org/synapse/issues/5767)) - Prevent a denial-of-service attack where cycles of redaction events would make Synapse spin infinitely. Thanks to `@lrizika:matrix.org` for identifying and responsibly disclosing this issue. ([0f2ecb961](https://github.com/matrix-org/synapse/commit/0f2ecb961)) - Prevent an attack where users could be joined or parted from public rooms without their consent. Thanks to @Dylanger for identifying and responsibly disclosing this issue. ([\#5744](https://github.com/matrix-org/synapse/issues/5744)) -- Fix a vulnerability where a federated server could spoof read-receipts from users on other servers. ([\#5743](https://github.com/matrix-org/synapse/issues/5743)) +- Fix a vulnerability where a federated server could spoof read-receipts from + users on other servers. Thanks to @Dylanger for identifying this issue too. ([\#5743](https://github.com/matrix-org/synapse/issues/5743)) Note that Synapse 1.2.0 also contained a security fix which was not correctly identified during the original release. The changelog below is now updated. From 992333b9954bec62e87cf5bf103fb5988d8bb063 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 26 Jul 2019 11:36:28 +0100 Subject: [PATCH 7/7] correct attributions in changelog --- CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2814d9586aa3..fa753bed1723 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,10 @@ This release includes *four* security fixes: - Fix a vulnerability where a federated server could spoof read-receipts from users on other servers. Thanks to @Dylanger for identifying this issue too. ([\#5743](https://github.com/matrix-org/synapse/issues/5743)) -Note that Synapse 1.2.0 also contained a security fix which was not correctly identified during the original release. The changelog below is now updated. +Additionally, the following fix was in Synapse **1.2.0**, but was not correctly +identified during the original release: + +- It was possible for a room moderator to send a redaction for an `m.room.create` event, which would downgrade the room to version 1. Thanks to `/dev/ponies` for identifying and responsibly disclosing this issue! ([\#5701](https://github.com/matrix-org/synapse/issues/5701)) Synapse 1.2.0 (2019-07-25) ==========================