matrix-org / matrix-spec

The Matrix protocol specification
Apache License 2.0
186 stars 94 forks source link

Better specify how to validate events #365

Open richvdh opened 6 years ago

richvdh commented 6 years ago

We should clearly specify how to validate an event that has been received over federation, and how the receiving server should behave when validation fails.

The sorts of things we should consider checking include:

Parts of this list overlap with the rules already set out for Authorization of PDUs.

Synapse currently checks many, but not all, of the things on this list, so there may well be rooms in existence which do not conform. Starting to check them now is problematic in that it may prevent servers from participating in those existing rooms. We should therefore consider whether it is reasonable to apply any additional checks now, or which should wait for a future room version.

We should also define the behaviour when a validation check is not met: should we ignore such events, or reject incoming pushes? For pulls, should we try to get the events from elsewhere?

turt2live commented 6 years ago

Related: matrix-org/matrix-spec-proposals#463

turt2live commented 6 years ago

Somehow I managed to miss this when digging for event validation information :(

Given the validation rules are almost certainly going to need to be a rooms v2 thing, I think we should go a bit more strongly down the path of validation. In general, the things listed to be considered in the draft seem sensible. I only have a few specific concerns:

On the point of figuring out how to handle invalid events, considering they would have already gone through the auth rules I don't think it's a good idea to reject them outright at the validation step. If the event is permitted to be in the room, then we should allow it to be there. That being said, servers should consider a soft failure approach to prevent badly formatted events from making it down to clients.

As a more minor point, the spec should clarify how events are meant to flow through the various algorithms. It's not entirely clear if validation is done before or after the auth rules, for instance.

To answer the question of "what about v1 rooms?", I think we should just say there that validation should be relaxed and only applied where it strictly applies (ie: use if membership == "join" rather than if membership not in [kick, ban, leave, join]).

richvdh commented 5 years ago

see also https://github.com/matrix-org/synapse/issues/1237

richvdh commented 5 years ago

see also matrix-org/matrix-spec#504

DMRobertson commented 2 years ago

schema compliance:

Note that the expectations here are sensitive to the room version in play; see #1044 #1045.

Kladki commented 2 months ago

whether it has all the required fields listed at https://matrix.org/docs/spec/server_server/unstable.html#persistent-data-unit-schema

Doesn't seem to be enforced (fully) by any server implementation, see #1904