summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-11-28 15:17:04 +0000
committerBrendan Abolivier <babolivier@matrix.org>2019-02-13 20:54:34 +0000
commitdbf7545ccd7c364a420ef844ce7a4b7cdbd67139 (patch)
tree2ee29f8f64cc68194976e3e46935a34cdb354988 /synapse
parentChange access tokens to be base64'ed 4 bytes (diff)
downloadsynapse-dbf7545ccd7c364a420ef844ce7a4b7cdbd67139.tar.xz
Mangle some more PDU fields
Diffstat (limited to 'synapse')
-rw-r--r--synapse/federation/federation_base.py19
-rw-r--r--synapse/federation/units.py6
-rw-r--r--synapse/handlers/device.py1
3 files changed, 23 insertions, 3 deletions
diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py
index 14406f5e70..758512bd86 100644
--- a/synapse/federation/federation_base.py
+++ b/synapse/federation/federation_base.py
@@ -318,7 +318,7 @@ def event_from_pdu_json(pdu_json, outlier=False):
 
     depth = pdu_json['depth']
     if not isinstance(depth, six.integer_types):
-        raise SynapseError(400, "Depth %r not an intger" % (depth, ),
+        raise SynapseError(400, "Depth %r not an integer" % (depth, ),
                            Codes.BAD_JSON)
 
     if depth < 0:
@@ -326,6 +326,23 @@ def event_from_pdu_json(pdu_json, outlier=False):
     elif depth > MAX_DEPTH:
         raise SynapseError(400, "Depth too large", Codes.BAD_JSON)
 
+    if "auth_events" in pdu_json:
+        pdu_json["auth_events"] = [
+            (e, {}) if isinstance(e, six.string_types) else e
+            for e in pdu_json["auth_events"]
+        ]
+
+    if "prev_events" in pdu_json:
+        pdu_json["prev_events"] = [
+            (e, {}) if isinstance(e, six.string_types) else e
+            for e in pdu_json["prev_events"]
+        ]
+
+    if "origin" not in pdu_json:
+        pdu_json["origin"] = get_domain_from_id(pdu_json["sender"])
+
+    logger.info("Unmangled event to: %s", pdu_json)
+
     event = FrozenEvent(
         pdu_json
     )
diff --git a/synapse/federation/units.py b/synapse/federation/units.py
index 6b329f26b4..308760d9b5 100644
--- a/synapse/federation/units.py
+++ b/synapse/federation/units.py
@@ -116,8 +116,11 @@ class Transaction(JsonEncodedObject):
 
 
 def _mangle_pdu(pdu_json):
+    pdu_json.pop("origin", None)
     pdu_json.pop("hashes", None)
     pdu_json.pop("signatures", None)
+    pdu_json.get("unsigned", {}).pop("age_ts", None)
+    pdu_json.get("unsigned", {}).pop("age", None)
 
     pdu_json["auth_events"] = list(_strip_hashes(pdu_json["auth_events"]))
     pdu_json["prev_events"] = list(_strip_hashes(pdu_json["prev_events"]))
@@ -129,6 +132,5 @@ def _mangle_pdu(pdu_json):
 
 def _strip_hashes(iterable):
     return (
-        (e, {})
-        for e, hashes in iterable
+        e for e, hashes in iterable
     )
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index 9e017116a9..ea3dd179b8 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -278,6 +278,7 @@ class DeviceHandler(BaseHandler):
             "device_list_key", position, rooms=room_ids,
         )
 
+        return
         if hosts:
             logger.info("Sending device list update notif to: %r", hosts)
             for host in hosts: