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

Commit 5d9e7e0

Browse files
committed
Merge branch 'master' into develop
2 parents 46ff99e + a4c8a2f commit 5d9e7e0

File tree

8 files changed

+214
-7
lines changed

8 files changed

+214
-7
lines changed

CHANGES.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
Users will stop receiving message updates via email for addresses that were previously linked to their account
22

3+
Synapse 1.41.1 (2021-08-31)
4+
===========================
5+
6+
Due to the two security issues highlighted below, server administrators are encouraged to update Synapse. We are not aware of these vulnerabilities being exploited in the wild.
7+
8+
Security advisory
9+
-----------------
10+
11+
The following issues are fixed in v1.41.1.
12+
13+
- **[GHSA-3x4c-pq33-4w3q](https://github.com/matrix-org/synapse/security/advisories/GHSA-3x4c-pq33-4w3q) / [CVE-2021-39164](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-39164): Enumerating a private room's list of members and their display names.**
14+
15+
If an unauthorized user both knows the Room ID of a private room *and* that room's history visibility is set to `shared`, then they may be able to enumerate the room's members, including their display names.
16+
17+
The unauthorized user must be on the same homeserver as a user who is a member of the target room.
18+
19+
Fixed by [52c7a51cf](https://github.com/matrix-org/synapse/commit/52c7a51cf).
20+
21+
- **[GHSA-jj53-8fmw-f2w2](https://github.com/matrix-org/synapse/security/advisories/GHSA-jj53-8fmw-f2w2) / [CVE-2021-39163](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-39163): Disclosing a private room's name, avatar, topic, and number of members.**
22+
23+
If an unauthorized user knows the Room ID of a private room, then its name, avatar, topic, and number of members may be disclosed through Group / Community features.
24+
25+
The unauthorized user must be on the same homeserver as a user who is a member of the target room, and their homeserver must allow non-administrators to create groups (`enable_group_creation` in the Synapse configuration; off by default).
26+
27+
Fixed by [cb35df940a](https://github.com/matrix-org/synapse/commit/cb35df940a), [\#10723](https://github.com/matrix-org/synapse/issues/10723).
28+
29+
Bugfixes
30+
--------
31+
32+
- Fix a regression introduced in Synapse 1.41 which broke email transmission on systems using older versions of the Twisted library. ([\#10713](https://github.com/matrix-org/synapse/issues/10713))
33+
334
Synapse 1.41.0 (2021-08-24)
435
===========================
536

changelog.d/10723.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix unauthorised exposure of room metadata to communities.

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
matrix-synapse-py3 (1.41.1) stable; urgency=high
2+
3+
* New synapse release 1.41.1.
4+
5+
-- Synapse Packaging team <[email protected]> Tue, 31 Aug 2021 12:59:10 +0100
6+
17
matrix-synapse-py3 (1.41.0) stable; urgency=medium
28

39
* New synapse release 1.41.0.

synapse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
except ImportError:
4848
pass
4949

50-
__version__ = "1.41.0"
50+
__version__ = "1.41.1"
5151

5252
if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
5353
# We import here so that we don't have to install a bunch of deps when

synapse/groups/groups_server.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ async def get_rooms_in_group(
332332
requester_user_id, group_id
333333
)
334334

335+
# Note! room_results["is_public"] is about whether the room is considered
336+
# public from the group's point of view. (i.e. whether non-group members
337+
# should be able to see the room is in the group).
338+
# This is not the same as whether the room itself is public (in the sense
339+
# of being visible in the room directory).
340+
# As such, room_results["is_public"] itself is not sufficient to determine
341+
# whether any given user is permitted to see the room's metadata.
335342
room_results = await self.store.get_rooms_in_group(
336343
group_id, include_private=is_user_in_group
337344
)
@@ -341,8 +348,15 @@ async def get_rooms_in_group(
341348
room_id = room_result["room_id"]
342349

343350
joined_users = await self.store.get_users_in_room(room_id)
351+
352+
# check the user is actually allowed to see the room before showing it to them
353+
allow_private = requester_user_id in joined_users
354+
344355
entry = await self.room_list_handler.generate_room_entry(
345-
room_id, len(joined_users), with_alias=False, allow_private=True
356+
room_id,
357+
len(joined_users),
358+
with_alias=False,
359+
allow_private=allow_private,
346360
)
347361

348362
if not entry:
@@ -354,7 +368,7 @@ async def get_rooms_in_group(
354368

355369
chunk.sort(key=lambda e: -e["num_joined_members"])
356370

357-
return {"chunk": chunk, "total_room_count_estimate": len(room_results)}
371+
return {"chunk": chunk, "total_room_count_estimate": len(chunk)}
358372

359373

360374
class GroupsServerHandler(GroupsServerWorkerHandler):

synapse/handlers/message.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,37 @@ async def get_state_events(
183183

184184
if not last_events:
185185
raise NotFoundError("Can't find event for token %s" % (at_token,))
186+
last_event = last_events[0]
187+
188+
# check whether the user is in the room at that time to determine
189+
# whether they should be treated as peeking.
190+
state_map = await self.state_store.get_state_for_event(
191+
last_event.event_id,
192+
StateFilter.from_types([(EventTypes.Member, user_id)]),
193+
)
194+
195+
joined = False
196+
membership_event = state_map.get((EventTypes.Member, user_id))
197+
if membership_event:
198+
joined = membership_event.membership == Membership.JOIN
199+
200+
is_peeking = not joined
186201

187202
visible_events = await filter_events_for_client(
188203
self.storage,
189204
user_id,
190205
last_events,
191206
filter_send_to_client=False,
207+
is_peeking=is_peeking,
192208
)
193209

194-
event = last_events[0]
195210
if visible_events:
196211
room_state_events = await self.state_store.get_state_for_events(
197-
[event.event_id], state_filter=state_filter
212+
[last_event.event_id], state_filter=state_filter
198213
)
199-
room_state: Mapping[Any, EventBase] = room_state_events[event.event_id]
214+
room_state: Mapping[Any, EventBase] = room_state_events[
215+
last_event.event_id
216+
]
200217
else:
201218
raise AuthError(
202219
403,

tests/rest/client/test_groups.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2021 The Matrix.org Foundation C.I.C.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from synapse.rest.client import groups, room
16+
17+
from tests import unittest
18+
from tests.unittest import override_config
19+
20+
21+
class GroupsTestCase(unittest.HomeserverTestCase):
22+
user_id = "@alice:test"
23+
room_creator_user_id = "@bob:test"
24+
25+
servlets = [room.register_servlets, groups.register_servlets]
26+
27+
@override_config({"enable_group_creation": True})
28+
def test_rooms_limited_by_visibility(self):
29+
group_id = "+spqr:test"
30+
31+
# Alice creates a group
32+
channel = self.make_request("POST", "/create_group", {"localpart": "spqr"})
33+
self.assertEquals(channel.code, 200, msg=channel.text_body)
34+
self.assertEquals(channel.json_body, {"group_id": group_id})
35+
36+
# Bob creates a private room
37+
room_id = self.helper.create_room_as(self.room_creator_user_id, is_public=False)
38+
self.helper.auth_user_id = self.room_creator_user_id
39+
self.helper.send_state(
40+
room_id, "m.room.name", {"name": "bob's secret room"}, tok=None
41+
)
42+
self.helper.auth_user_id = self.user_id
43+
44+
# Alice adds the room to her group.
45+
channel = self.make_request(
46+
"PUT", f"/groups/{group_id}/admin/rooms/{room_id}", {}
47+
)
48+
self.assertEquals(channel.code, 200, msg=channel.text_body)
49+
self.assertEquals(channel.json_body, {})
50+
51+
# Alice now tries to retrieve the room list of the space.
52+
channel = self.make_request("GET", f"/groups/{group_id}/rooms")
53+
self.assertEquals(channel.code, 200, msg=channel.text_body)
54+
self.assertEquals(
55+
channel.json_body, {"chunk": [], "total_room_count_estimate": 0}
56+
)

tests/rest/client/test_rooms.py

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from synapse.api.errors import HttpResponseException
3030
from synapse.handlers.pagination import PurgeStatus
3131
from synapse.rest import admin
32-
from synapse.rest.client import account, directory, login, profile, room
32+
from synapse.rest.client import account, directory, login, profile, room, sync
3333
from synapse.types import JsonDict, RoomAlias, UserID, create_requester
3434
from synapse.util.stringutils import random_string
3535

@@ -381,6 +381,8 @@ def test_leave_permissions(self):
381381
class RoomsMemberListTestCase(RoomBase):
382382
"""Tests /rooms/$room_id/members/list REST events."""
383383

384+
servlets = RoomBase.servlets + [sync.register_servlets]
385+
384386
user_id = "@sid1:red"
385387

386388
def test_get_member_list(self):
@@ -397,6 +399,86 @@ def test_get_member_list_no_permission(self):
397399
channel = self.make_request("GET", "/rooms/%s/members" % room_id)
398400
self.assertEquals(403, channel.code, msg=channel.result["body"])
399401

402+
def test_get_member_list_no_permission_with_at_token(self):
403+
"""
404+
Tests that a stranger to the room cannot get the member list
405+
(in the case that they use an at token).
406+
"""
407+
room_id = self.helper.create_room_as("@someone.else:red")
408+
409+
# first sync to get an at token
410+
channel = self.make_request("GET", "/sync")
411+
self.assertEquals(200, channel.code)
412+
sync_token = channel.json_body["next_batch"]
413+
414+
# check that permission is denied for @sid1:red to get the
415+
# memberships of @someone.else:red's room.
416+
channel = self.make_request(
417+
"GET",
418+
f"/rooms/{room_id}/members?at={sync_token}",
419+
)
420+
self.assertEquals(403, channel.code, msg=channel.result["body"])
421+
422+
def test_get_member_list_no_permission_former_member(self):
423+
"""
424+
Tests that a former member of the room can not get the member list.
425+
"""
426+
# create a room, invite the user and the user joins
427+
room_id = self.helper.create_room_as("@alice:red")
428+
self.helper.invite(room_id, "@alice:red", self.user_id)
429+
self.helper.join(room_id, self.user_id)
430+
431+
# check that the user can see the member list to start with
432+
channel = self.make_request("GET", "/rooms/%s/members" % room_id)
433+
self.assertEquals(200, channel.code, msg=channel.result["body"])
434+
435+
# ban the user
436+
self.helper.change_membership(room_id, "@alice:red", self.user_id, "ban")
437+
438+
# check the user can no longer see the member list
439+
channel = self.make_request("GET", "/rooms/%s/members" % room_id)
440+
self.assertEquals(403, channel.code, msg=channel.result["body"])
441+
442+
def test_get_member_list_no_permission_former_member_with_at_token(self):
443+
"""
444+
Tests that a former member of the room can not get the member list
445+
(in the case that they use an at token).
446+
"""
447+
# create a room, invite the user and the user joins
448+
room_id = self.helper.create_room_as("@alice:red")
449+
self.helper.invite(room_id, "@alice:red", self.user_id)
450+
self.helper.join(room_id, self.user_id)
451+
452+
# sync to get an at token
453+
channel = self.make_request("GET", "/sync")
454+
self.assertEquals(200, channel.code)
455+
sync_token = channel.json_body["next_batch"]
456+
457+
# check that the user can see the member list to start with
458+
channel = self.make_request(
459+
"GET", "/rooms/%s/members?at=%s" % (room_id, sync_token)
460+
)
461+
self.assertEquals(200, channel.code, msg=channel.result["body"])
462+
463+
# ban the user (Note: the user is actually allowed to see this event and
464+
# state so that they know they're banned!)
465+
self.helper.change_membership(room_id, "@alice:red", self.user_id, "ban")
466+
467+
# invite a third user and let them join
468+
self.helper.invite(room_id, "@alice:red", "@bob:red")
469+
self.helper.join(room_id, "@bob:red")
470+
471+
# now, with the original user, sync again to get a new at token
472+
channel = self.make_request("GET", "/sync")
473+
self.assertEquals(200, channel.code)
474+
sync_token = channel.json_body["next_batch"]
475+
476+
# check the user can no longer see the updated member list
477+
channel = self.make_request(
478+
"GET", "/rooms/%s/members?at=%s" % (room_id, sync_token)
479+
)
480+
self.assertEquals(403, channel.code, msg=channel.result["body"])
481+
400482
def test_get_member_list_mixed_memberships(self):
401483
room_creator = "@some_other_guy:red"
402484
room_id = self.helper.create_room_as(room_creator)

0 commit comments

Comments
 (0)