From 187a6787a9fad8bd1b1dc684c714c574a12fad9d Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 20 Jul 2023 15:12:12 -0700 Subject: [PATCH 1/2] add proposed changes + update test --- synapse/events/utils.py | 8 +++++--- tests/events/test_utils.py | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index ecfc5c0568c6..c890833b1d1e 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -136,11 +136,13 @@ def add_fields(*fields: str) -> None: ] elif event_type == EventTypes.Create: - # MSC2176 rules state that create events cannot be redacted. if room_version.updated_redaction_rules: - return event_dict + # MSC2176 rules state that create events cannot have their `content` redacted. + new_content = event_dict["content"] + elif not room_version.implicit_room_creator: + # Some room versions give meaning to `creator` + add_fields("creator") - add_fields("creator") elif event_type == EventTypes.JoinRules: add_fields("join_rule") if room_version.restricted_join_rule: diff --git a/tests/events/test_utils.py b/tests/events/test_utils.py index 6a52af4d82af..978612e4322f 100644 --- a/tests/events/test_utils.py +++ b/tests/events/test_utils.py @@ -225,9 +225,14 @@ def test_create(self) -> None: }, ) - # After MSC2176, create events get nothing redacted. + # After MSC2176, create events should preserve field `content` self.run_test( - {"type": "m.room.create", "content": {"not_a_real_key": True}}, + { + "type": "m.room.create", + "content": {"not_a_real_key": True}, + "origin": "some_homeserver", + "nonsense_field": "some_random_garbage", + }, { "type": "m.room.create", "content": {"not_a_real_key": True}, From 95ab66ba51781853b4a5ed7a9db7603eb84ba745 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 20 Jul 2023 15:23:53 -0700 Subject: [PATCH 2/2] newsfragement --- changelog.d/15973.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15973.bugfix diff --git a/changelog.d/15973.bugfix b/changelog.d/15973.bugfix new file mode 100644 index 000000000000..c9280d003733 --- /dev/null +++ b/changelog.d/15973.bugfix @@ -0,0 +1 @@ +Properly handle redactions of creation events.