mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Validate message, topic and name event contents
This commit is contained in:
parent
fa4b610ae3
commit
63810c777d
@ -68,3 +68,8 @@ class EventTypes(object):
|
|||||||
PowerLevels = "m.room.power_levels"
|
PowerLevels = "m.room.power_levels"
|
||||||
Aliases = "m.room.aliases"
|
Aliases = "m.room.aliases"
|
||||||
Redaction = "m.room.redaction"
|
Redaction = "m.room.redaction"
|
||||||
|
|
||||||
|
# These are used for validation
|
||||||
|
Message = "m.room.message"
|
||||||
|
Topic = "m.room.topic"
|
||||||
|
Name = "m.room.name"
|
||||||
|
@ -69,3 +69,24 @@ class EventValidator(object):
|
|||||||
self.validate(event)
|
self.validate(event)
|
||||||
|
|
||||||
UserID.from_string(event.sender)
|
UserID.from_string(event.sender)
|
||||||
|
|
||||||
|
if event.type == EventTypes.Message:
|
||||||
|
strings = [
|
||||||
|
"body",
|
||||||
|
"msgtype",
|
||||||
|
]
|
||||||
|
|
||||||
|
self._ensure_strings(event.content, strings)
|
||||||
|
|
||||||
|
elif event.type == EventTypes.Topic:
|
||||||
|
self._ensure_strings(event.content, ["topic"])
|
||||||
|
|
||||||
|
elif event.type == EventTypes.Name:
|
||||||
|
self._ensure_strings(event.content, ["name"])
|
||||||
|
|
||||||
|
def _ensure_strings(self, d, keys):
|
||||||
|
for s in keys:
|
||||||
|
if s not in d:
|
||||||
|
raise SynapseError(400, "'%s' not in content" % (s,))
|
||||||
|
if not isinstance(d[s], basestring):
|
||||||
|
raise SynapseError(400, "Not '%s' a string type" % (s,))
|
||||||
|
@ -141,7 +141,7 @@ class MessageHandler(BaseHandler):
|
|||||||
def handle_event(self, event_dict):
|
def handle_event(self, event_dict):
|
||||||
builder = self.event_builder_factory.new(event_dict)
|
builder = self.event_builder_factory.new(event_dict)
|
||||||
|
|
||||||
self.validator.validate(builder)
|
self.validator.validate_new(builder)
|
||||||
|
|
||||||
if builder.type == EventTypes.Member:
|
if builder.type == EventTypes.Member:
|
||||||
membership = builder.content.get("membership", None)
|
membership = builder.content.get("membership", None)
|
||||||
|
Loading…
Reference in New Issue
Block a user