Mangle some more PDU fields

This commit is contained in:
Erik Johnston 2018-11-28 15:17:04 +00:00 committed by Brendan Abolivier
parent 306b670371
commit a99c2f56b5
3 changed files with 21 additions and 3 deletions

View file

@ -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:
@ -335,6 +335,21 @@ def event_from_pdu_json(pdu_json, outlier=False):
for dest in destinations
}
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(

View file

@ -120,8 +120,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"]))
@ -147,8 +150,7 @@ def _mangle_pdu(pdu_json):
def _strip_hashes(iterable):
return (
(e, {})
for e, hashes in iterable
e for e, hashes in iterable
)

View file

@ -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: