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

Implement MSC2730: verifiable forwarded events#8078

Closed
tulir wants to merge 10 commits into
matrix-org:developfrom
tulir:verifiable-forwarded-events
Closed

Implement MSC2730: verifiable forwarded events#8078
tulir wants to merge 10 commits into
matrix-org:developfrom
tulir:verifiable-forwarded-events

Conversation

@tulir
Copy link
Copy Markdown
Member

@tulir tulir commented Aug 13, 2020

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 the net.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

  • Pull request is based on the develop branch
  • Pull request includes a changelog file.
  • Pull request includes a sign off
  • Code style is correct (run the linters)

@anoadragon453
Copy link
Copy Markdown
Member

@tulir is this PR ready for review?

@tulir
Copy link
Copy Markdown
Member Author

tulir commented Oct 1, 2020

I think it is

@clokep clokep requested a review from a team October 1, 2020 13:46


class FederationHandler(BaseHandler):
class FederationHandler(BaseHandler, FederationBase):
Copy link
Copy Markdown
Member

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.


return fetched_events

_forwarded_key = "net.maunium.msc2730.forwarded"
Copy link
Copy Markdown
Member

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]]:
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member

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).

Comment on lines +709 to +710
except SynapseError:
return False, None
Copy link
Copy Markdown
Member

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)
Copy link
Copy Markdown
Member

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
Copy link
Copy Markdown
Member

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.

@richvdh
Copy link
Copy Markdown
Member

richvdh commented Oct 12, 2020

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!

@richvdh richvdh closed this Oct 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants