mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Merge pull request #4166 from matrix-org/erikj/drop_unknown_events
Drop incoming events from federation for unknown rooms
This commit is contained in:
commit
db5a1c059a
1
changelog.d/4165.misc
Normal file
1
changelog.d/4165.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Drop incoming events from federation for unknown rooms
|
@ -162,8 +162,30 @@ class FederationServer(FederationBase):
|
|||||||
p["age_ts"] = request_time - int(p["age"])
|
p["age_ts"] = request_time - int(p["age"])
|
||||||
del p["age"]
|
del p["age"]
|
||||||
|
|
||||||
|
# We try and pull out an event ID so that if later checks fail we
|
||||||
|
# can log something sensible. We don't mandate an event ID here in
|
||||||
|
# case future event formats get rid of the key.
|
||||||
|
possible_event_id = p.get("event_id", "<Unknown>")
|
||||||
|
|
||||||
|
# Now we get the room ID so that we can check that we know the
|
||||||
|
# version of the room.
|
||||||
|
room_id = p.get("room_id")
|
||||||
|
if not room_id:
|
||||||
|
logger.info(
|
||||||
|
"Ignoring PDU as does not have a room_id. Event ID: %s",
|
||||||
|
possible_event_id,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
# In future we will actually use the room version to parse the
|
||||||
|
# PDU into an event.
|
||||||
|
yield self.store.get_room_version(room_id)
|
||||||
|
except NotFoundError:
|
||||||
|
logger.info("Ignoring PDU for unknown room_id: %s", room_id)
|
||||||
|
continue
|
||||||
|
|
||||||
event = event_from_pdu_json(p)
|
event = event_from_pdu_json(p)
|
||||||
room_id = event.room_id
|
|
||||||
pdus_by_room.setdefault(room_id, []).append(event)
|
pdus_by_room.setdefault(room_id, []).append(event)
|
||||||
|
|
||||||
pdu_results = {}
|
pdu_results = {}
|
||||||
|
@ -202,24 +202,19 @@ class FederationHandler(BaseHandler):
|
|||||||
self.room_queues[room_id].append((pdu, origin))
|
self.room_queues[room_id].append((pdu, origin))
|
||||||
return
|
return
|
||||||
|
|
||||||
# If we're no longer in the room just ditch the event entirely. This
|
# If we're not in the room just ditch the event entirely. This is
|
||||||
# is probably an old server that has come back and thinks we're still
|
# probably an old server that has come back and thinks we're still in
|
||||||
# in the room (or we've been rejoined to the room by a state reset).
|
# the room (or we've been rejoined to the room by a state reset).
|
||||||
#
|
#
|
||||||
# If we were never in the room then maybe our database got vaped and
|
# Note that if we were never in the room then we would have already
|
||||||
# we should check if we *are* in fact in the room. If we are then we
|
# dropped the event, since we wouldn't know the room version.
|
||||||
# can magically rejoin the room.
|
|
||||||
is_in_room = yield self.auth.check_host_in_room(
|
is_in_room = yield self.auth.check_host_in_room(
|
||||||
room_id,
|
room_id,
|
||||||
self.server_name
|
self.server_name
|
||||||
)
|
)
|
||||||
if not is_in_room:
|
if not is_in_room:
|
||||||
was_in_room = yield self.store.was_host_joined(
|
|
||||||
pdu.room_id, self.server_name,
|
|
||||||
)
|
|
||||||
if was_in_room:
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"[%s %s] Ignoring PDU from %s as we've left the room",
|
"[%s %s] Ignoring PDU from %s as we're not in the room",
|
||||||
room_id, event_id, origin,
|
room_id, event_id, origin,
|
||||||
)
|
)
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
@ -557,38 +552,6 @@ class FederationHandler(BaseHandler):
|
|||||||
room_id, event_id, event,
|
room_id, event_id, event,
|
||||||
)
|
)
|
||||||
|
|
||||||
# FIXME (erikj): Awful hack to make the case where we are not currently
|
|
||||||
# in the room work
|
|
||||||
# If state and auth_chain are None, then we don't need to do this check
|
|
||||||
# as we already know we have enough state in the DB to handle this
|
|
||||||
# event.
|
|
||||||
if state and auth_chain and not event.internal_metadata.is_outlier():
|
|
||||||
is_in_room = yield self.auth.check_host_in_room(
|
|
||||||
room_id,
|
|
||||||
self.server_name
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
is_in_room = True
|
|
||||||
|
|
||||||
if not is_in_room:
|
|
||||||
logger.info(
|
|
||||||
"[%s %s] Got event for room we're not in",
|
|
||||||
room_id, event_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
yield self._persist_auth_tree(
|
|
||||||
origin, auth_chain, state, event
|
|
||||||
)
|
|
||||||
except AuthError as e:
|
|
||||||
raise FederationError(
|
|
||||||
"ERROR",
|
|
||||||
e.code,
|
|
||||||
e.msg,
|
|
||||||
affected=event_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
event_ids = set()
|
event_ids = set()
|
||||||
if state:
|
if state:
|
||||||
event_ids |= {e.event_id for e in state}
|
event_ids |= {e.event_id for e in state}
|
||||||
|
Loading…
Reference in New Issue
Block a user