diff --git a/eventversion.go b/eventversion.go index 9f38585d..596458e2 100644 --- a/eventversion.go +++ b/eventversion.go @@ -39,6 +39,14 @@ type IRoomVersion interface { DomainlessRoomIDs() bool PrivilegedCreators() bool StateDAGs() bool + // returns true if this room version requires a "creator" field + // in the m.room.create event content (room versions 1–10). The field + // was removed in room version 11, where the creator is instead derived from + // the event sender. + CreatorInCreateEvent() bool + // StrictEventByteLimits returns true if this room version enforces field + // length limits in bytes rather than Unicode codepoints (introduced in v11 for synapse). + StrictEventByteLimits() bool } type KnownRoomVersionFunc func(RoomVersion) bool @@ -110,6 +118,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: disallowKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV1, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV1, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV1, @@ -130,6 +139,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: disallowKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV1, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV1, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV1, @@ -150,6 +160,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: disallowKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -170,6 +181,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: disallowKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -190,6 +202,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: disallowKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -210,6 +223,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: disallowKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -230,6 +244,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -250,6 +265,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -270,6 +286,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -290,6 +307,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -310,6 +328,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV2, + strictEventByteLimits: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -330,6 +349,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV3, + strictEventByteLimits: true, // v3 versions relax the room ID check as the room ID has no domain now. newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV3, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV3, @@ -353,6 +373,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -373,6 +394,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: disallowRestrictedJoins, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -392,6 +414,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ parsePowerLevelsFunc: parsePowerLevels, checkKnockingAllowedFunc: checkKnocking, checkCreateEvent: checkCreateEventV1, + creatorInCreateEvent: true, newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2, newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2, @@ -436,6 +459,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{ checkKnockingAllowedFunc: checkKnocking, checkRestrictedJoinAllowedFunc: allowRestrictedJoins, checkCreateEvent: checkCreateEventV3, + strictEventByteLimits: true, // v3 versions relax the room ID check as the room ID has no domain now. newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV3, newEventFromTrustedJSONFunc: newEventFromTrustedJSONV3, @@ -529,6 +553,13 @@ type RoomVersionImpl struct { domainlessRoomID bool // creators have infinite PL privilegedCreators bool + // the m.room.create content includes a "creator" field + // (room versions 1–10). This is distinct from privilegedCreators, which + // governs power-levels; this flag only controls whether the field + // must be present in the create event content. + creatorInCreateEvent bool + // field length limits are in bytes rather than Unicode codepoints + strictEventByteLimits bool // Events form two graphs, a state DAG and an event DAG. stateDAGs bool checkRestrictedJoin func(ctx context.Context, localServerName spec.ServerName, roomQuerier RestrictedRoomJoinQuerier, roomID spec.RoomID, senderID spec.SenderID, privilegedCreators bool) (string, error) @@ -562,6 +593,14 @@ func (v RoomVersionImpl) PrivilegedCreators() bool { return v.privilegedCreators } +func (v RoomVersionImpl) CreatorInCreateEvent() bool { + return v.creatorInCreateEvent +} + +func (v RoomVersionImpl) StrictEventByteLimits() bool { + return v.strictEventByteLimits +} + // StateResAlgorithm returns the state resolution for the given room version. func (v RoomVersionImpl) StateResAlgorithm() StateResAlgorithm { return v.stateResAlgorithm