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

Commit

Permalink
Merge pull request #3642 from matrix-org/rav/another_room_id_check
Browse files Browse the repository at this point in the history
Check room visibility for /event/ requests
  • Loading branch information
richvdh authored Aug 2, 2018
2 parents a937497 + 8cefc69 commit 50d9d97
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion changelog.d/3641.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix a potential event disclosure issue
Fix a potential issue where servers could request events for rooms they have not joined.
1 change: 1 addition & 0 deletions changelog.d/3642.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a potential issue where users could see events in private joins before they joined
25 changes: 21 additions & 4 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
from twisted.internet import defer

from synapse.api.constants import EventTypes, Membership
from synapse.api.errors import AuthError
from synapse.events import EventBase
from synapse.events.utils import serialize_event
from synapse.types import UserID
from synapse.util.logutils import log_function
from synapse.visibility import filter_events_for_client

from ._base import BaseHandler

Expand Down Expand Up @@ -129,11 +131,13 @@ def get_stream(self, auth_user_id, pagin_config, timeout=0,
class EventHandler(BaseHandler):

@defer.inlineCallbacks
def get_event(self, user, event_id):
def get_event(self, user, room_id, event_id):
"""Retrieve a single specified event.
Args:
user (synapse.types.UserID): The user requesting the event
room_id (str|None): The expected room id. We'll return None if the
event's room does not match.
event_id (str): The event ID to obtain.
Returns:
dict: An event, or None if there is no event matching this ID.
Expand All @@ -142,13 +146,26 @@ def get_event(self, user, event_id):
AuthError if the user does not have the rights to inspect this
event.
"""
event = yield self.store.get_event(event_id)
event = yield self.store.get_event(event_id, check_room_id=room_id)

if not event:
defer.returnValue(None)
return

if hasattr(event, "room_id"):
yield self.auth.check_joined_room(event.room_id, user.to_string())
users = yield self.store.get_users_in_room(event.room_id)
is_peeking = user.to_string() not in users

filtered = yield filter_events_for_client(
self.store,
user.to_string(),
[event],
is_peeking=is_peeking
)

if not filtered:
raise AuthError(
403,
"You don't have permission to access that event."
)

defer.returnValue(event)
2 changes: 1 addition & 1 deletion synapse/rest/client/v1/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, hs):
@defer.inlineCallbacks
def on_GET(self, request, event_id):
requester = yield self.auth.get_user_by_req(request)
event = yield self.event_handler.get_event(requester.user, event_id)
event = yield self.event_handler.get_event(requester.user, None, event_id)

time_now = self.clock.time_msec()
if event:
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def __init__(self, hs):
@defer.inlineCallbacks
def on_GET(self, request, room_id, event_id):
requester = yield self.auth.get_user_by_req(request)
event = yield self.event_handler.get_event(requester.user, event_id)
event = yield self.event_handler.get_event(requester.user, room_id, event_id)

time_now = self.clock.time_msec()
if event:
Expand Down

0 comments on commit 50d9d97

Please sign in to comment.