-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Implement MSC2730: verifiable forwarded events #8078
Conversation
@tulir is this PR ready for review? |
I think it is |
@@ -108,7 +109,7 @@ class _NewEventInfo: | |||
auth_events = attr.ib(type=Optional[MutableStateMap[EventBase]], default=None) | |||
|
|||
|
|||
class FederationHandler(BaseHandler): | |||
class FederationHandler(BaseHandler, FederationBase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ftr, FederationBase
is something I wish would go away. Those utility functions need to be brought in by composition, not inheritance.
@@ -683,6 +684,41 @@ async def _get_events_from_store_or_dest( | |||
|
|||
return fetched_events | |||
|
|||
_forwarded_key = "net.maunium.msc2730.forwarded" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants go in UPPER_CASE at the top of the file.
|
||
async def _validate_forwarded_event( | ||
self, event: EventBase | ||
) -> Tuple[bool, Optional[str]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just return the event id if it's valid, and None
if it's not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(alternatively: what does it mean if valid
is False, but an event id is returned? Some docstring would help here).
except SynapseError: | ||
return False, None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a general rule, eating exceptions like this without giving any clue about what the exception was leads to hard-to-debug failures. I'd recommend logging something before returning.
return False, None | ||
|
||
try: | ||
checked_evt = await self._check_sigs_and_hash(room_version, source_evt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is some horrible attack where you can claim that an event is for a different room version than it is, and hence get it to pass the hash checks when it shouldn't...
# Pass through the old event ID to the new unsigned data | ||
event_id = unsigned[self._data_key]["event_id"] | ||
elif not has_forward_meta: | ||
content[self._data_key] = event_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
careful: I think this modifies the original event, stored in the cache. You need to copy content
before modifying it.
Hi @tulir, thanks for this! It looks generally like a sensible idea, and from the point of view of the MSC process I certainly think there is enough here to demonstrate a workable implementation, but I'm afraid I don't think we can accept this into mainline synapse until the MSC gets wider acceptance, so I'm going to close it for now. We'll be very happy to reopen once the MSC progresses! |
This adds an implementation of matrix-org/matrix-spec-proposals#2730 to Synapse, i.e. it adds a new
PUT /_matrix/client/unstable/net.maunium.msc2730/rooms/{roomId}/event/{eventId}/forward/{targetRoomId}/{txnId}
endpoint and implements validation of incoming events that have thenet.maunium.msc2730
key.Element web implementation: matrix-org/matrix-js-sdk#1439 / matrix-org/matrix-react-sdk#5117
Signed-off-by: Tulir Asokan <tulir@maunium.net>
Pull Request Checklist