mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Merge pull request #5805 from matrix-org/erikj/validate_state
Validate well known state events are state events.
This commit is contained in:
commit
55a0c98d16
1
changelog.d/5805.misc
Normal file
1
changelog.d/5805.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Deny sending well known state types as non-state events.
|
@ -95,10 +95,10 @@ class EventValidator(object):
|
|||||||
|
|
||||||
elif event.type == EventTypes.Topic:
|
elif event.type == EventTypes.Topic:
|
||||||
self._ensure_strings(event.content, ["topic"])
|
self._ensure_strings(event.content, ["topic"])
|
||||||
|
self._ensure_state_event(event)
|
||||||
elif event.type == EventTypes.Name:
|
elif event.type == EventTypes.Name:
|
||||||
self._ensure_strings(event.content, ["name"])
|
self._ensure_strings(event.content, ["name"])
|
||||||
|
self._ensure_state_event(event)
|
||||||
elif event.type == EventTypes.Member:
|
elif event.type == EventTypes.Member:
|
||||||
if "membership" not in event.content:
|
if "membership" not in event.content:
|
||||||
raise SynapseError(400, "Content has not membership key")
|
raise SynapseError(400, "Content has not membership key")
|
||||||
@ -106,6 +106,7 @@ class EventValidator(object):
|
|||||||
if event.content["membership"] not in Membership.LIST:
|
if event.content["membership"] not in Membership.LIST:
|
||||||
raise SynapseError(400, "Invalid membership key")
|
raise SynapseError(400, "Invalid membership key")
|
||||||
|
|
||||||
|
self._ensure_state_event(event)
|
||||||
elif event.type == EventTypes.Tombstone:
|
elif event.type == EventTypes.Tombstone:
|
||||||
if "replacement_room" not in event.content:
|
if "replacement_room" not in event.content:
|
||||||
raise SynapseError(400, "Content has no replacement_room key")
|
raise SynapseError(400, "Content has no replacement_room key")
|
||||||
@ -115,9 +116,15 @@ class EventValidator(object):
|
|||||||
400, "Tombstone cannot reference the room it was sent in"
|
400, "Tombstone cannot reference the room it was sent in"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._ensure_state_event(event)
|
||||||
|
|
||||||
def _ensure_strings(self, d, keys):
|
def _ensure_strings(self, d, keys):
|
||||||
for s in keys:
|
for s in keys:
|
||||||
if s not in d:
|
if s not in d:
|
||||||
raise SynapseError(400, "'%s' not in content" % (s,))
|
raise SynapseError(400, "'%s' not in content" % (s,))
|
||||||
if not isinstance(d[s], string_types):
|
if not isinstance(d[s], string_types):
|
||||||
raise SynapseError(400, "'%s' not a string type" % (s,))
|
raise SynapseError(400, "'%s' not a string type" % (s,))
|
||||||
|
|
||||||
|
def _ensure_state_event(self, event):
|
||||||
|
if not event.is_state():
|
||||||
|
raise SynapseError(400, "'%s' must be state events" % (event.type,))
|
||||||
|
Loading…
Reference in New Issue
Block a user