mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Enforce compatibility when processing make_join requests
Reject make_join requests from servers which do not support the room version. Also include the room version in the response.
This commit is contained in:
parent
0ca459ea33
commit
0d63d93ca8
@ -58,6 +58,7 @@ class Codes(object):
|
|||||||
CANNOT_LEAVE_SERVER_NOTICE_ROOM = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM"
|
CANNOT_LEAVE_SERVER_NOTICE_ROOM = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM"
|
||||||
MAU_LIMIT_EXCEEDED = "M_MAU_LIMIT_EXCEEDED"
|
MAU_LIMIT_EXCEEDED = "M_MAU_LIMIT_EXCEEDED"
|
||||||
UNSUPPORTED_ROOM_VERSION = "M_UNSUPPORTED_ROOM_VERSION"
|
UNSUPPORTED_ROOM_VERSION = "M_UNSUPPORTED_ROOM_VERSION"
|
||||||
|
INCOMPATIBLE_ROOM_VERSION = "M_INCOMPATIBLE_ROOM_VERSION"
|
||||||
|
|
||||||
|
|
||||||
class CodeMessageException(RuntimeError):
|
class CodeMessageException(RuntimeError):
|
||||||
@ -287,6 +288,27 @@ class LimitExceededError(SynapseError):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class IncompatibleRoomVersionError(SynapseError):
|
||||||
|
"""A server is trying to join a room whose version it does not support."""
|
||||||
|
|
||||||
|
def __init__(self, room_version):
|
||||||
|
super(IncompatibleRoomVersionError, self).__init__(
|
||||||
|
code=400,
|
||||||
|
msg="Your homeserver does not support the features required to "
|
||||||
|
"join this room",
|
||||||
|
errcode=Codes.INCOMPATIBLE_ROOM_VERSION,
|
||||||
|
)
|
||||||
|
|
||||||
|
self._room_version = room_version
|
||||||
|
|
||||||
|
def error_dict(self):
|
||||||
|
return cs_error(
|
||||||
|
self.msg,
|
||||||
|
self.errcode,
|
||||||
|
room_version=self._room_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def cs_error(msg, code=Codes.UNKNOWN, **kwargs):
|
def cs_error(msg, code=Codes.UNKNOWN, **kwargs):
|
||||||
""" Utility method for constructing an error response for client-server
|
""" Utility method for constructing an error response for client-server
|
||||||
interactions.
|
interactions.
|
||||||
|
@ -27,7 +27,13 @@ from twisted.internet.abstract import isIPAddress
|
|||||||
from twisted.python import failure
|
from twisted.python import failure
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes
|
from synapse.api.constants import EventTypes
|
||||||
from synapse.api.errors import AuthError, FederationError, NotFoundError, SynapseError
|
from synapse.api.errors import (
|
||||||
|
AuthError,
|
||||||
|
FederationError,
|
||||||
|
IncompatibleRoomVersionError,
|
||||||
|
NotFoundError,
|
||||||
|
SynapseError,
|
||||||
|
)
|
||||||
from synapse.crypto.event_signing import compute_event_signature
|
from synapse.crypto.event_signing import compute_event_signature
|
||||||
from synapse.federation.federation_base import FederationBase, event_from_pdu_json
|
from synapse.federation.federation_base import FederationBase, event_from_pdu_json
|
||||||
from synapse.federation.persistence import TransactionActions
|
from synapse.federation.persistence import TransactionActions
|
||||||
@ -323,12 +329,21 @@ class FederationServer(FederationBase):
|
|||||||
defer.returnValue((200, resp))
|
defer.returnValue((200, resp))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_make_join_request(self, origin, room_id, user_id):
|
def on_make_join_request(self, origin, room_id, user_id, supported_versions):
|
||||||
origin_host, _ = parse_server_name(origin)
|
origin_host, _ = parse_server_name(origin)
|
||||||
yield self.check_server_matches_acl(origin_host, room_id)
|
yield self.check_server_matches_acl(origin_host, room_id)
|
||||||
|
|
||||||
|
room_version = yield self.store.get_room_version(room_id)
|
||||||
|
if room_version not in supported_versions:
|
||||||
|
logger.warn("Room version %s not in %s", room_version, supported_versions)
|
||||||
|
raise IncompatibleRoomVersionError(room_version=room_version)
|
||||||
|
|
||||||
pdu = yield self.handler.on_make_join_request(room_id, user_id)
|
pdu = yield self.handler.on_make_join_request(room_id, user_id)
|
||||||
time_now = self._clock.time_msec()
|
time_now = self._clock.time_msec()
|
||||||
defer.returnValue({"event": pdu.get_pdu_json(time_now)})
|
defer.returnValue({
|
||||||
|
"event": pdu.get_pdu_json(time_now),
|
||||||
|
"room_version": room_version,
|
||||||
|
})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_invite_request(self, origin, content):
|
def on_invite_request(self, origin, content):
|
||||||
|
@ -431,9 +431,31 @@ class FederationMakeJoinServlet(BaseFederationServlet):
|
|||||||
PATH = "/make_join/(?P<context>[^/]*)/(?P<user_id>[^/]*)"
|
PATH = "/make_join/(?P<context>[^/]*)/(?P<user_id>[^/]*)"
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, origin, content, query, context, user_id):
|
def on_GET(self, origin, _content, query, context, user_id):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
origin (unicode): The authenticated server_name of the calling server
|
||||||
|
|
||||||
|
_content (None): (GETs don't have bodies)
|
||||||
|
|
||||||
|
query (dict[bytes, list[bytes]]): Query params from the request.
|
||||||
|
|
||||||
|
**kwargs (dict[unicode, unicode]): the dict mapping keys to path
|
||||||
|
components as specified in the path match regexp.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Deferred[(int, object)|None]: either (response code, response object) to
|
||||||
|
return a JSON response, or None if the request has already been handled.
|
||||||
|
"""
|
||||||
|
versions = query.get(b'ver')
|
||||||
|
if versions is not None:
|
||||||
|
supported_versions = [v.decode("utf-8") for v in versions]
|
||||||
|
else:
|
||||||
|
supported_versions = ["1"]
|
||||||
|
|
||||||
content = yield self.handler.on_make_join_request(
|
content = yield self.handler.on_make_join_request(
|
||||||
origin, context, user_id,
|
origin, context, user_id,
|
||||||
|
supported_versions=supported_versions,
|
||||||
)
|
)
|
||||||
defer.returnValue((200, content))
|
defer.returnValue((200, content))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user