mirror of
https://github.com/element-hq/synapse
synced 2024-09-03 23:40:07 +00:00
Actually, the old prune_event function was non-deterministic, so no point keeping it around :(
This commit is contained in:
parent
8dae5c8108
commit
9bace3a367
2 changed files with 4 additions and 91 deletions
|
@ -94,85 +94,6 @@ def prune_event(event):
|
|||
)
|
||||
|
||||
|
||||
def old_prune_event(event):
|
||||
"""This is an old and buggy version of the prune event function. The
|
||||
difference between this and the new version is that when including dicts
|
||||
in the content they were included as frozen_dicts rather than dicts. This
|
||||
caused the JSON encoder to encode as a list of the keys rather than the
|
||||
dict.
|
||||
"""
|
||||
event_type = event.type
|
||||
|
||||
allowed_keys = [
|
||||
"event_id",
|
||||
"sender",
|
||||
"room_id",
|
||||
"hashes",
|
||||
"signatures",
|
||||
"content",
|
||||
"type",
|
||||
"state_key",
|
||||
"depth",
|
||||
"prev_events",
|
||||
"prev_state",
|
||||
"auth_events",
|
||||
"origin",
|
||||
"origin_server_ts",
|
||||
"membership",
|
||||
]
|
||||
|
||||
event_dict = event.get_dict()
|
||||
|
||||
new_content = {}
|
||||
|
||||
def add_fields(*fields):
|
||||
for field in fields:
|
||||
if field in event.content:
|
||||
# This is the line that is buggy: event.content may return
|
||||
# a frozen_dict which the json encoders encode as lists rather
|
||||
# than dicts.
|
||||
new_content[field] = event.content[field]
|
||||
|
||||
if event_type == EventTypes.Member:
|
||||
add_fields("membership")
|
||||
elif event_type == EventTypes.Create:
|
||||
add_fields("creator")
|
||||
elif event_type == EventTypes.JoinRules:
|
||||
add_fields("join_rule")
|
||||
elif event_type == EventTypes.PowerLevels:
|
||||
add_fields(
|
||||
"users",
|
||||
"users_default",
|
||||
"events",
|
||||
"events_default",
|
||||
"events_default",
|
||||
"state_default",
|
||||
"ban",
|
||||
"kick",
|
||||
"redact",
|
||||
)
|
||||
elif event_type == EventTypes.Aliases:
|
||||
add_fields("aliases")
|
||||
|
||||
allowed_fields = {
|
||||
k: v
|
||||
for k, v in event_dict.items()
|
||||
if k in allowed_keys
|
||||
}
|
||||
|
||||
allowed_fields["content"] = new_content
|
||||
|
||||
allowed_fields["unsigned"] = {}
|
||||
|
||||
if "age_ts" in event.unsigned:
|
||||
allowed_fields["unsigned"]["age_ts"] = event.unsigned["age_ts"]
|
||||
|
||||
return type(event)(
|
||||
allowed_fields,
|
||||
internal_metadata_dict=event.internal_metadata.get_dict()
|
||||
)
|
||||
|
||||
|
||||
def format_event_raw(d):
|
||||
return d
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.events.utils import prune_event, old_prune_event
|
||||
from synapse.events.utils import prune_event
|
||||
|
||||
from syutil.jsonutil import encode_canonical_json
|
||||
|
||||
|
@ -96,18 +96,10 @@ class FederationBase(object):
|
|||
redacted_event = prune_event(pdu)
|
||||
redacted_pdu_json = redacted_event.get_pdu_json()
|
||||
|
||||
old_redacted = old_prune_event(pdu)
|
||||
old_redacted_pdu_json = old_redacted.get_pdu_json()
|
||||
|
||||
try:
|
||||
try:
|
||||
yield self.keyring.verify_json_for_server(
|
||||
pdu.origin, old_redacted_pdu_json
|
||||
)
|
||||
except SynapseError:
|
||||
yield self.keyring.verify_json_for_server(
|
||||
pdu.origin, redacted_pdu_json
|
||||
)
|
||||
yield self.keyring.verify_json_for_server(
|
||||
pdu.origin, redacted_pdu_json
|
||||
)
|
||||
except SynapseError:
|
||||
logger.warn(
|
||||
"Signature check failed for %s redacted to %s",
|
||||
|
|
Loading…
Reference in a new issue