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

Commit cb88ed9

Browse files
authored
_check_event_auth: move event validation earlier (#10988)
There's little point in doing a fancy state reconciliation dance if the event itself is invalid. Likewise, there's no point checking it again in `_check_for_soft_fail`.
1 parent 6f6e956 commit cb88ed9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

changelog.d/10988.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up some of the federation event authentication code for clarity.

synapse/handlers/federation_event.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1250,9 +1250,18 @@ async def _check_event_auth(
12501250
# This method should only be used for non-outliers
12511251
assert not event.internal_metadata.outlier
12521252

1253+
# first of all, check that the event itself is valid.
12531254
room_version = await self._store.get_room_version_id(event.room_id)
12541255
room_version_obj = KNOWN_ROOM_VERSIONS[room_version]
12551256

1257+
try:
1258+
validate_event_for_room_version(room_version_obj, event)
1259+
except AuthError as e:
1260+
logger.warning("While validating received event %r: %s", event, e)
1261+
# TODO: use a different rejected reason here?
1262+
context.rejected = RejectedReason.AUTH_ERROR
1263+
return context
1264+
12561265
# calculate what the auth events *should* be, to use as a basis for auth.
12571266
prev_state_ids = await context.get_prev_state_ids()
12581267
auth_events_ids = self._event_auth_handler.compute_auth_events(
@@ -1286,7 +1295,6 @@ async def _check_event_auth(
12861295
auth_events_for_auth = calculated_auth_event_map
12871296

12881297
try:
1289-
validate_event_for_room_version(room_version_obj, event)
12901298
check_auth_rules_for_event(room_version_obj, event, auth_events_for_auth)
12911299
except AuthError as e:
12921300
logger.warning("Failed auth resolution for %r because %s", event, e)
@@ -1399,9 +1407,6 @@ async def _check_for_soft_fail(
13991407
}
14001408

14011409
try:
1402-
# TODO: skip the call to validate_event_for_room_version? we should already
1403-
# have validated the event.
1404-
validate_event_for_room_version(room_version_obj, event)
14051410
check_auth_rules_for_event(room_version_obj, event, current_auth_events)
14061411
except AuthError as e:
14071412
logger.warning(

0 commit comments

Comments
 (0)