mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 19:15:04 -04:00
Fix 404 on /sync
when the last event is a redaction of an unknown/purged event (#12905)
Currently, we try to pull the event corresponding to a sync token from the database. However, when we fetch redaction events, we check the target of that redaction (because we aren't allowed to send redactions to clients without validating them). So, if the sync token points to a redaction of an event that we don't have, we have a problem. It turns out we don't really need that event, and can just work with its ID and metadata, which sidesteps the whole problem.
This commit is contained in:
parent
5949ab86f8
commit
79dadf7216
6 changed files with 129 additions and 65 deletions
|
@ -162,16 +162,7 @@ async def filter_events_for_client(
|
|||
state = event_id_to_state[event.event_id]
|
||||
|
||||
# get the room_visibility at the time of the event.
|
||||
visibility_event = state.get(_HISTORY_VIS_KEY, None)
|
||||
if visibility_event:
|
||||
visibility = visibility_event.content.get(
|
||||
"history_visibility", HistoryVisibility.SHARED
|
||||
)
|
||||
else:
|
||||
visibility = HistoryVisibility.SHARED
|
||||
|
||||
if visibility not in VISIBILITY_PRIORITY:
|
||||
visibility = HistoryVisibility.SHARED
|
||||
visibility = get_effective_room_visibility_from_state(state)
|
||||
|
||||
# Always allow history visibility events on boundaries. This is done
|
||||
# by setting the effective visibility to the least restrictive
|
||||
|
@ -267,6 +258,23 @@ async def filter_events_for_client(
|
|||
return [ev for ev in filtered_events if ev]
|
||||
|
||||
|
||||
def get_effective_room_visibility_from_state(state: StateMap[EventBase]) -> str:
|
||||
"""Get the actual history vis, from a state map including the history_visibility event
|
||||
|
||||
Handles missing and invalid history visibility events.
|
||||
"""
|
||||
visibility_event = state.get(_HISTORY_VIS_KEY, None)
|
||||
if not visibility_event:
|
||||
return HistoryVisibility.SHARED
|
||||
|
||||
visibility = visibility_event.content.get(
|
||||
"history_visibility", HistoryVisibility.SHARED
|
||||
)
|
||||
if visibility not in VISIBILITY_PRIORITY:
|
||||
visibility = HistoryVisibility.SHARED
|
||||
return visibility
|
||||
|
||||
|
||||
async def filter_events_for_server(
|
||||
storage: StorageControllers,
|
||||
server_name: str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue