summary refs log tree commit diff
path: root/synapse/events
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-12 10:56:14 +0000
committerErik Johnston <erik@matrix.org>2014-12-12 11:01:09 +0000
commit63810c777d8c02bc6fefa2a4bcfacb7f4df21ba2 (patch)
treebc85baa07a4715dab2fd7961c69058a2ac2a267b /synapse/events
parentFix stream test. Make sure we add join to auth_events for invitiations (diff)
downloadsynapse-63810c777d8c02bc6fefa2a4bcfacb7f4df21ba2.tar.xz
Validate message, topic and name event contents
Diffstat (limited to 'synapse/events')
-rw-r--r--synapse/events/validator.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/synapse/events/validator.py b/synapse/events/validator.py
index 47830aa985..ebc6c30e62 100644
--- a/synapse/events/validator.py
+++ b/synapse/events/validator.py
@@ -69,3 +69,24 @@ class EventValidator(object):
         self.validate(event)
 
         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,))