matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.79k stars 2.13k forks source link

Drop invalid PDUs instead of erroring #7543

Open clokep opened 4 years ago

clokep commented 4 years ago

This is based on a conversation at https://github.com/matrix-org/matrix-doc/pull/2540#discussion_r427973050, summarized below:

Currently when an incoming federation event is "bad" for some reason it is rejected by returning a 400 error. This is particularly troublesome in endpoints where multiple events are handled at once, as the entire transaction gets rejected.

Reasons an event might be rejected include:

There are three proposed options for this situation:

  1. silently drop the event. I would argue that we should not be blackholing events, ever: it feels like we'll end up dropping events unexpectedly.
    1. send an error back in the response, against the event's event_id. This, of course, requires the recipient to parse the json, remove a couple of properties, then re-encode it using canonicaljson (which, you recall, is theoretically impossible) to calculate the event id. That sounds like a tautology to me. It also requires servers which don't even support older room versions to still accept transactions with floats in them. So that leaves us with:
    2. reject the whole lot.

It is potentially difficult to return a sensible error since (theoretically) you might not even be able to parse the event data and thus it is proposed to silently drop these events for now.

clokep commented 4 years ago

@erikjohnston / @richvdh Does this sound like a reasonable summary of that conversation and what needs to be done?

Open questions from my side include:

richvdh commented 4 years ago

beware that the term "rejected" is fraught with danger: we tend to use it for the class of events which we accept onto the DAG but do not include in the room state or send to clients (that's useful, because we want to preserve the structure of the DAG where possible). I'm not sure we have a term for the class of events which are too mangled to even add to the room DAG, though I tend to refer to them as "invalid".

clokep commented 4 years ago

Alright. That clears it up a bit! 👍 I think this would be relatively straightforward then.

richvdh commented 2 years ago

Related: https://github.com/matrix-org/matrix-spec/issues/365