summary refs log tree commit diff
path: root/synapse/events/validator.py
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2020-05-14 13:24:01 -0400
committerGitHub <noreply@github.com>2020-05-14 13:24:01 -0400
commit56b66db78a3a6a22f65b219f4dc12899111f742b (patch)
tree6af77f84427554db2efe6fcd8bfe087911e357b9 /synapse/events/validator.py
parentMerge branch 'master' into develop (diff)
downloadsynapse-56b66db78a3a6a22f65b219f4dc12899111f742b.tar.xz
Strictly enforce canonicaljson requirements in a new room version (#7381)
Diffstat (limited to 'synapse/events/validator.py')
-rw-r--r--synapse/events/validator.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/synapse/events/validator.py b/synapse/events/validator.py
index 9b90c9ce04..b001c64bb4 100644
--- a/synapse/events/validator.py
+++ b/synapse/events/validator.py
@@ -18,6 +18,7 @@ from six import integer_types, string_types
 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.events.utils import validate_canonicaljson
 from synapse.types import EventID, RoomID, UserID
 
 
@@ -55,6 +56,12 @@ class EventValidator(object):
             if not isinstance(getattr(event, s), string_types):
                 raise SynapseError(400, "'%s' not a string type" % (s,))
 
+        # Depending on the room version, ensure the data is spec compliant JSON.
+        if event.room_version.strict_canonicaljson:
+            # Note that only the client controlled portion of the event is
+            # checked, since we trust the portions of the event we created.
+            validate_canonicaljson(event.content)
+
         if event.type == EventTypes.Aliases:
             if "aliases" in event.content:
                 for alias in event.content["aliases"]: