forked from MirrorHub/synapse
Remove room_version
param from validate_event_for_room_version
Instead, use the `room_version` property of the event we're validating. The `room_version` was originally added as a parameter somewhere around #4482, but really it's been redundant since #6875 added a `room_version` field to `EventBase`.
This commit is contained in:
parent
2959184a42
commit
68be42f6b6
6 changed files with 14 additions and 14 deletions
|
@ -45,9 +45,7 @@ if typing.TYPE_CHECKING:
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def validate_event_for_room_version(
|
def validate_event_for_room_version(event: "EventBase") -> None:
|
||||||
room_version_obj: RoomVersion, event: "EventBase"
|
|
||||||
) -> None:
|
|
||||||
"""Ensure that the event complies with the limits, and has the right signatures
|
"""Ensure that the event complies with the limits, and has the right signatures
|
||||||
|
|
||||||
NB: does not *validate* the signatures - it assumes that any signatures present
|
NB: does not *validate* the signatures - it assumes that any signatures present
|
||||||
|
@ -60,12 +58,10 @@ def validate_event_for_room_version(
|
||||||
NB: This is used to check events that have been received over federation. As such,
|
NB: This is used to check events that have been received over federation. As such,
|
||||||
it can only enforce the checks specified in the relevant room version, to avoid
|
it can only enforce the checks specified in the relevant room version, to avoid
|
||||||
a split-brain situation where some servers accept such events, and others reject
|
a split-brain situation where some servers accept such events, and others reject
|
||||||
them.
|
them. See also EventValidator, which contains extra checks which are applied only to
|
||||||
|
locally-generated events.
|
||||||
TODO: consider moving this into EventValidator
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
room_version_obj: the version of the room which contains this event
|
|
||||||
event: the event to be checked
|
event: the event to be checked
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
|
@ -103,7 +99,7 @@ def validate_event_for_room_version(
|
||||||
raise AuthError(403, "Event not signed by sending server")
|
raise AuthError(403, "Event not signed by sending server")
|
||||||
|
|
||||||
is_invite_via_allow_rule = (
|
is_invite_via_allow_rule = (
|
||||||
room_version_obj.msc3083_join_rules
|
event.room_version.msc3083_join_rules
|
||||||
and event.type == EventTypes.Member
|
and event.type == EventTypes.Member
|
||||||
and event.membership == Membership.JOIN
|
and event.membership == Membership.JOIN
|
||||||
and EventContentFields.AUTHORISING_USER in event.content
|
and EventContentFields.AUTHORISING_USER in event.content
|
||||||
|
|
|
@ -35,6 +35,10 @@ class EventValidator:
|
||||||
def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
|
def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
|
||||||
"""Validates the event has roughly the right format
|
"""Validates the event has roughly the right format
|
||||||
|
|
||||||
|
Suitable for checking a locally-created event. It has stricter checks than
|
||||||
|
is appropriate for an event received over federation (for which, see
|
||||||
|
event_auth.validate_event_for_room_version)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
event: The event to validate.
|
event: The event to validate.
|
||||||
config: The homeserver's configuration.
|
config: The homeserver's configuration.
|
||||||
|
|
|
@ -1206,7 +1206,7 @@ class FederationHandler:
|
||||||
event.internal_metadata.send_on_behalf_of = self.hs.hostname
|
event.internal_metadata.send_on_behalf_of = self.hs.hostname
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_event_for_room_version(room_version_obj, event)
|
validate_event_for_room_version(event)
|
||||||
await self._event_auth_handler.check_auth_rules_from_context(
|
await self._event_auth_handler.check_auth_rules_from_context(
|
||||||
room_version_obj, event, context
|
room_version_obj, event, context
|
||||||
)
|
)
|
||||||
|
@ -1258,7 +1258,7 @@ class FederationHandler:
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_event_for_room_version(room_version_obj, event)
|
validate_event_for_room_version(event)
|
||||||
await self._event_auth_handler.check_auth_rules_from_context(
|
await self._event_auth_handler.check_auth_rules_from_context(
|
||||||
room_version_obj, event, context
|
room_version_obj, event, context
|
||||||
)
|
)
|
||||||
|
|
|
@ -1453,7 +1453,7 @@ class FederationEventHandler:
|
||||||
|
|
||||||
context = EventContext.for_outlier(self._storage_controllers)
|
context = EventContext.for_outlier(self._storage_controllers)
|
||||||
try:
|
try:
|
||||||
validate_event_for_room_version(room_version_obj, event)
|
validate_event_for_room_version(event)
|
||||||
check_auth_rules_for_event(room_version_obj, event, auth)
|
check_auth_rules_for_event(room_version_obj, event, auth)
|
||||||
except AuthError as e:
|
except AuthError as e:
|
||||||
logger.warning("Rejecting %r because %s", event, e)
|
logger.warning("Rejecting %r because %s", event, e)
|
||||||
|
@ -1501,7 +1501,7 @@ class FederationEventHandler:
|
||||||
room_version_obj = KNOWN_ROOM_VERSIONS[room_version]
|
room_version_obj = KNOWN_ROOM_VERSIONS[room_version]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_event_for_room_version(room_version_obj, event)
|
validate_event_for_room_version(event)
|
||||||
except AuthError as e:
|
except AuthError as e:
|
||||||
logger.warning("While validating received event %r: %s", event, e)
|
logger.warning("While validating received event %r: %s", event, e)
|
||||||
# TODO: use a different rejected reason here?
|
# TODO: use a different rejected reason here?
|
||||||
|
|
|
@ -1297,7 +1297,7 @@ class EventCreationHandler:
|
||||||
assert event.content["membership"] == Membership.LEAVE
|
assert event.content["membership"] == Membership.LEAVE
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
validate_event_for_room_version(room_version_obj, event)
|
validate_event_for_room_version(event)
|
||||||
await self._event_auth_handler.check_auth_rules_from_context(
|
await self._event_auth_handler.check_auth_rules_from_context(
|
||||||
room_version_obj, event, context
|
room_version_obj, event, context
|
||||||
)
|
)
|
||||||
|
|
|
@ -227,7 +227,7 @@ class RoomCreationHandler:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
old_room_version = await self.store.get_room_version(old_room_id)
|
old_room_version = await self.store.get_room_version(old_room_id)
|
||||||
validate_event_for_room_version(old_room_version, tombstone_event)
|
validate_event_for_room_version(tombstone_event)
|
||||||
await self._event_auth_handler.check_auth_rules_from_context(
|
await self._event_auth_handler.check_auth_rules_from_context(
|
||||||
old_room_version, tombstone_event, tombstone_context
|
old_room_version, tombstone_event, tombstone_context
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue