summary refs log tree commit diff
path: root/synapse/events
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2023-05-15 08:58:09 -0400
committerGitHub <noreply@github.com>2023-05-15 12:58:09 +0000
commitba6b21c81e67583ac850eab5d96fe5666620d614 (patch)
treef470e1e8a9b5f114fa0942aa114fb3af97669634 /synapse/events
parentRevert "Bump pillow from 9.4.0 to 9.5.0 (#15593)" (diff)
downloadsynapse-ba6b21c81e67583ac850eab5d96fe5666620d614.tar.xz
Implement MSC3389 to protect relations from redaction. (#15565)
MSC3389 proposes protecting the relation type & parent event ID
from redaction. This keeps the relation information intact after
redaction which helps with some UX flaws (e.g. deleting an
event causes it to no longer be in a thread, which is confusing).
Diffstat (limited to 'synapse/events')
-rw-r--r--synapse/events/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py
index 0802eb1963..e540f1582a 100644
--- a/synapse/events/utils.py
+++ b/synapse/events/utils.py
@@ -171,6 +171,18 @@ def prune_event_dict(room_version: RoomVersion, event_dict: JsonDict) -> JsonDic
     elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_MARKER:
         add_fields(EventContentFields.MSC2716_INSERTION_EVENT_REFERENCE)
 
+    # Protect the rel_type and event_id fields under the m.relates_to field.
+    if room_version.msc3389_relation_redactions:
+        relates_to = event_dict["content"].get("m.relates_to")
+        if isinstance(relates_to, collections.abc.Mapping):
+            new_relates_to = {}
+            for field in ("rel_type", "event_id"):
+                if field in relates_to:
+                    new_relates_to[field] = relates_to[field]
+            # Only include a non-empty relates_to field.
+            if new_relates_to:
+                new_content["m.relates_to"] = new_relates_to
+
     allowed_fields = {k: v for k, v in event_dict.items() if k in allowed_keys}
 
     allowed_fields["content"] = new_content