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

Commit

Permalink
Properly handle redactions of creation events (matrix-org#15973)
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay authored and Fizzadar committed Aug 31, 2023
1 parent 94b1bb4 commit ce20e5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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

0 comments on commit ce20e5e

Please sign in to comment.