From fcf01dd88e738e5745c17c7740e0d72b8bbbcb66 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 19 Jun 2017 11:33:40 +0100 Subject: [PATCH 1/2] Reject local events that don't round trip the DB --- synapse/handlers/message.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index a04f634c5..5585ee85c 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -34,6 +34,7 @@ from canonicaljson import encode_canonical_json import logging import random +import ujson logger = logging.getLogger(__name__) @@ -498,6 +499,14 @@ class MessageHandler(BaseHandler): logger.warn("Denying new event %r because %s", event, err) raise err + # Ensure that we can round trip before trying to persist in db + try: + dump = ujson.dumps(event.content) + load = ujson.loads(dump) + except: + logger.exception("Failed to encode content: %r", event.content) + raise + yield self.maybe_kick_guest_users(event, context) if event.type == EventTypes.CanonicalAlias: From 1bce3e6b35eb3acba335c69c12ec06da9c7051df Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 26 Jun 2017 14:03:27 +0100 Subject: [PATCH 2/2] Remove unused variables --- synapse/handlers/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 5585ee85c..24c9ffdb2 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -502,7 +502,7 @@ class MessageHandler(BaseHandler): # Ensure that we can round trip before trying to persist in db try: dump = ujson.dumps(event.content) - load = ujson.loads(dump) + ujson.loads(dump) except: logger.exception("Failed to encode content: %r", event.content) raise