Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Properly handle redactions of creation events #15973

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15973.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly handle redactions of creation events.
8 changes: 5 additions & 3 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions tests/events/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down