-
-
Notifications
You must be signed in to change notification settings - Fork 126
Description
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:
- json compliance:
- does it conform to the rules of canonicaljson (eg no floats, no bigints)?
- Does it have invalid UTF-8 (invalid byte sequences, overlong encodings, things which decode to the UTF-16 surrogates or to codepoints above U+10FFFF)?
- schema compliance:
- whether it has all the required fields listed at https://matrix.org/docs/spec/server_server/unstable.html#persistent-data-unit-schema
- whether those fields (and the optional ones) have the expected types, and match the relevant grammars, including length limits (cf Pick a unit for describing string length #1001)
- event-type-specific tests: eg, if it is a membership event, whether
content.membershipis a known value - whether or not it has a
state_key, depending on its event type - does the event as a whole exceed the length limit?
- whether the
originmatches the sender sending the event, for pushed transactions. - whether the
senderandevent_idmatch theorigin(except for join events) - whether the
creatoron a create event matches thesenderand theroom_id - whether it has a "sensible" number of
prev_events - signatures: whether the event has been signed by the origin (and the sender's server, where different).
- also, whether the signing key was valid at the time the signature was made.
- hashes: whether the event's content matches the content hash
- whether hashes in prev_events and auth_events correspond to the hashes on events we have (though this will probably be made much simpler by MSC: Replace event IDs with hashes matrix-spec-proposals#1640)
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?