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

Sanity-check room ids in event auth #6530

Merged
merged 1 commit into from
Dec 13, 2019
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
2 changes: 2 additions & 0 deletions changelog.d/6530.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve sanity-checking when receiving events over federation.

12 changes: 12 additions & 0 deletions synapse/event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def check(room_version, event, auth_events, do_sig_check=True, do_size_check=Tru
if not hasattr(event, "room_id"):
raise AuthError(500, "Event has no room_id: %s" % event)

room_id = event.room_id

# I'm not really expecting to get auth events in the wrong room, but let's
# sanity-check it
for auth_event in auth_events.values():
if auth_event.room_id != room_id:
raise Exception(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to 500 or 403?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that I think the problem has happened somewhere else if we get this far, I think a 500 is more appropriate. Consider it as an assertion.

Tbh I think that our habit of trying to decide what HTTP error codes we should return in the depths of utility functions is an anti-pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair

"During auth for event %s in room %s, found event %s in the state "
"which is in room %s"
% (event.event_id, room_id, auth_event.event_id, auth_event.room_id)
)

if do_sig_check:
sender_domain = get_domain_from_id(event.sender)

Expand Down