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

Commit 9f5baec

Browse files
committed
Reconcile state when processing incoming events during faster joins
In order to handle incoming events over federation during a faster join, we need to relax the auth rules. Specifically, we need to accept that we may not have the sender's membership in our view of the room state. However, it should be in the `auth_events`, and state-resolving the auth events against our view should give the right thing.
1 parent 58fb17d commit 9f5baec

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

synapse/handlers/federation_event.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,13 +1528,36 @@ async def _check_event_auth(
15281528
# https://spec.matrix.org/v1.3/server-server-api/#checks-performed-on-receipt-of-a-pdu:
15291529
# 5. Passes authorization rules based on the state before the event,
15301530
# otherwise it is rejected.
1531-
event_types = event_auth.auth_types_for_event(event.room_version, event)
1532-
prev_state_ids = await context.get_prev_state_ids(
1533-
StateFilter.from_types(event_types)
1534-
)
1531+
#
1532+
# ... however, if we only have partial state for the room, then there is a good
1533+
# chance that we'll be missing some of the state needed to auth the new event.
1534+
# So, we state-resolve the auth event that we are given against the state that
1535+
# we know about, which ensures things like bans are applied.
1536+
if context.partial_state:
1537+
room_version = await self._store.get_room_version_id(event.room_id)
1538+
1539+
local_state_id_map = await context.get_prev_state_ids()
1540+
claimed_auth_events_id_map = {
1541+
(ev.type, ev.state_key): ev.event_id for ev in claimed_auth_events
1542+
}
1543+
1544+
state_for_auth_id_map = (
1545+
await self._state_resolution_handler.resolve_events_with_store(
1546+
event.room_id,
1547+
room_version,
1548+
[local_state_id_map, claimed_auth_events_id_map],
1549+
event_map=None,
1550+
state_res_store=StateResolutionStore(self._store),
1551+
)
1552+
)
1553+
else:
1554+
event_types = event_auth.auth_types_for_event(event.room_version, event)
1555+
state_for_auth_id_map = await context.get_prev_state_ids(
1556+
StateFilter.from_types(event_types)
1557+
)
15351558

15361559
calculated_auth_event_ids = self._event_auth_handler.compute_auth_events(
1537-
event, prev_state_ids, for_verification=True
1560+
event, state_for_auth_id_map, for_verification=True
15381561
)
15391562

15401563
# if those are the same, we're done here.

0 commit comments

Comments
 (0)