Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Block clients from sending server ACLs that lock the local server out. #8708

Merged
merged 6 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ files =
synapse/config,
synapse/event_auth.py,
synapse/events/builder.py,
synapse/events/validator.py,
synapse/events/spamcheck.py,
synapse/federation,
synapse/handlers/_base.py,
Expand Down
20 changes: 11 additions & 9 deletions synapse/events/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Union

from synapse.api.constants import MAX_ALIAS_LENGTH, EventTypes, Membership
from synapse.api.errors import Codes, SynapseError
from synapse.api.room_versions import EventFormatVersions
from synapse.config.homeserver import HomeServerConfig
from synapse.events import EventBase
from synapse.events.builder import EventBuilder
from synapse.events.utils import validate_canonicaljson
from synapse.types import EventID, RoomID, UserID


class EventValidator:
def validate_new(self, event, config):
def validate_new(self, event: EventBase, config: HomeServerConfig):
"""Validates the event has roughly the right format

Args:
event (FrozenEvent): The event to validate.
config (Config): The homeserver's configuration.
event The event to validate.
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
config: The homeserver's configuration.
"""
self.validate_builder(event)

Expand Down Expand Up @@ -76,12 +81,12 @@ def validate_new(self, event, config):
if event.type == EventTypes.Retention:
self._validate_retention(event)

def _validate_retention(self, event):
def _validate_retention(self, event: EventBase):
"""Checks that an event that defines the retention policy for a room respects the
format enforced by the spec.

Args:
event (FrozenEvent): The event to validate.
event: The event to validate.
"""
if not event.is_state():
raise SynapseError(code=400, msg="must be a state event")
Expand Down Expand Up @@ -116,13 +121,10 @@ def _validate_retention(self, event):
errcode=Codes.BAD_JSON,
)

def validate_builder(self, event):
def validate_builder(self, event: Union[EventBase, EventBuilder]):
"""Validates that the builder/event has roughly the right format. Only
checks values that we expect a proto event to have, rather than all the
fields an event would have

Args:
event (EventBuilder|FrozenEvent)
"""

strings = ["room_id", "sender", "type"]
Expand Down