summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2019-07-31 16:44:19 +0200
committerGitHub <noreply@github.com>2019-07-31 16:44:19 +0200
commitc862d5baf6d861428a6b41a49d8b8329bf93759c (patch)
tree8dfc84967e34d14fc0e7799f067cbe5e048025c5
parentMerge pull request #5702 from matrix-org/babolivier/3pid-invite (diff)
parentIgnore redactions of redactions in get_events_as_list (diff)
downloadsynapse-c862d5baf6d861428a6b41a49d8b8329bf93759c.tar.xz
Check room ID and type of redacted event (#5784) dinsic_2019-07-31
Check room ID and type of redacted event
-rw-r--r--synapse/storage/events_worker.py49
1 files changed, 32 insertions, 17 deletions
diff --git a/synapse/storage/events_worker.py b/synapse/storage/events_worker.py

index cc7df5cf14..5dc49822b5 100644 --- a/synapse/storage/events_worker.py +++ b/synapse/storage/events_worker.py
@@ -255,6 +255,26 @@ class EventsWorkerStore(SQLBaseStore): # didn't have the redacted event at the time, so we recheck on read # instead. if not allow_rejected and entry.event.type == EventTypes.Redaction: + orig_event_info = yield self._simple_select_one( + table="events", + keyvalues={"event_id": entry.event.redacts}, + retcols=["sender", "room_id", "type"], + allow_none=True, + ) + + if not orig_event_info: + # We don't have the event that is being redacted, so we + # assume that the event isn't authorized for now. (If we + # later receive the event, then we will always redact + # it anyway, since we have this redaction) + continue + + if orig_event_info["room_id"] != entry.event.room_id: + # Don't process redactions if the redacted event doesn't belong to the + # redaction's room. + logger.info("Ignoring redation in another room.") + continue + if entry.event.internal_metadata.need_to_check_redaction(): # XXX: we need to avoid calling get_event here. # @@ -277,27 +297,13 @@ class EventsWorkerStore(SQLBaseStore): # 2. have _get_event_from_row just call the first half of # that - orig_sender = yield self._simple_select_one_onecol( - table="events", - keyvalues={"event_id": entry.event.redacts}, - retcol="sender", - allow_none=True, - ) - expected_domain = get_domain_from_id(entry.event.sender) if ( - orig_sender - and get_domain_from_id(orig_sender) == expected_domain + get_domain_from_id(orig_event_info["sender"]) == expected_domain ): # This redaction event is allowed. Mark as not needing a # recheck. entry.event.internal_metadata.recheck_redaction = False - else: - # We don't have the event that is being redacted, so we - # assume that the event isn't authorized for now. (If we - # later receive the event, then we will always redact - # it anyway, since we have this redaction) - continue if allow_rejected or not entry.event.rejected_reason: if check_redacted and entry.redacted_event: @@ -532,7 +538,7 @@ class EventsWorkerStore(SQLBaseStore): ) redacted_event = None - if redacted: + if redacted and original_ev.type != EventTypes.Redaction: redacted_event = prune_event(original_ev) redaction_id = yield self._simple_select_one_onecol( @@ -564,9 +570,18 @@ class EventsWorkerStore(SQLBaseStore): # recheck. because.internal_metadata.recheck_redaction = False else: - # Senders don't match, so the event isn't actually redacted + # Senders don't match, so the event isn't actually + # redacted redacted_event = None + if because.room_id != original_ev.room_id: + redacted_event = None + else: + # The lack of a redaction likely means that the redaction is invalid + # and therefore not returned by get_event, so it should be safe to + # just ignore it here. + redacted_event = None + cache_entry = _EventCacheEntry( event=original_ev, redacted_event=redacted_event )