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

Commit dede23f

Browse files
committed
Merge tag 'v1.13.0rc2' into develop
Synapse 1.13.0rc2 (2020-05-14) ============================== Bugfixes -------- - Fix a long-standing bug which could cause messages not to be sent over federation, when state events with state keys matching user IDs (such as custom user statuses) were received. ([\#7376](#7376)) - Restore compatibility with non-compliant clients during the user interactive authentication process, fixing a problem introduced in v1.13.0rc1. ([\#7483](#7483)) Internal Changes ---------------- - Fix linting errors in new version of Flake8. ([\#7470](#7470))
2 parents 1124111 + 75fbc1a commit dede23f

File tree

7 files changed

+95
-68
lines changed

7 files changed

+95
-68
lines changed

CHANGES.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
Synapse 1.13.0rc2 (2020-05-14)
2+
==============================
3+
4+
Bugfixes
5+
--------
6+
7+
- Fix a long-standing bug which could cause messages not to be sent over federation, when state events with state keys matching user IDs (such as custom user statuses) were received. ([\#7376](https://github.com/matrix-org/synapse/issues/7376))
8+
- Restore compatibility with non-compliant clients during the user interactive authentication process, fixing a problem introduced in v1.13.0rc1. ([\#7483](https://github.com/matrix-org/synapse/issues/7483))
9+
10+
Internal Changes
11+
----------------
12+
13+
- Fix linting errors in new version of Flake8. ([\#7470](https://github.com/matrix-org/synapse/issues/7470))
14+
15+
116
Synapse 1.13.0rc1 (2020-05-11)
217
==============================
318

synapse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
except ImportError:
3737
pass
3838

39-
__version__ = "1.13.0rc1"
39+
__version__ = "1.13.0rc2"
4040

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

synapse/handlers/auth.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ async def check_auth(
252252
clientdict: Dict[str, Any],
253253
clientip: str,
254254
description: str,
255-
validate_clientdict: bool = True,
256255
) -> Tuple[dict, dict, str]:
257256
"""
258257
Takes a dictionary sent by the client in the login / registration
@@ -278,10 +277,6 @@ async def check_auth(
278277
description: A human readable string to be displayed to the user that
279278
describes the operation happening on their account.
280279
281-
validate_clientdict: Whether to validate that the operation happening
282-
on the account has not changed. If this is false,
283-
the client dict is persisted instead of validated.
284-
285280
Returns:
286281
A tuple of (creds, params, session_id).
287282
@@ -346,26 +341,30 @@ async def check_auth(
346341

347342
# Ensure that the queried operation does not vary between stages of
348343
# the UI authentication session. This is done by generating a stable
349-
# comparator based on the URI, method, and client dict (minus the
350-
# auth dict) and storing it during the initial query. Subsequent
344+
# comparator and storing it during the initial query. Subsequent
351345
# queries ensure that this comparator has not changed.
352-
if validate_clientdict:
353-
session_comparator = (session.uri, session.method, session.clientdict)
354-
comparator = (uri, method, clientdict)
355-
else:
356-
session_comparator = (session.uri, session.method) # type: ignore
357-
comparator = (uri, method) # type: ignore
358-
359-
if session_comparator != comparator:
346+
#
347+
# The comparator is based on the requested URI and HTTP method. The
348+
# client dict (minus the auth dict) should also be checked, but some
349+
# clients are not spec compliant, just warn for now if the client
350+
# dict changes.
351+
if (session.uri, session.method) != (uri, method):
360352
raise SynapseError(
361353
403,
362354
"Requested operation has changed during the UI authentication session.",
363355
)
364356

365-
# For backwards compatibility the registration endpoint persists
366-
# changes to the client dict instead of validating them.
367-
if not validate_clientdict:
368-
await self.store.set_ui_auth_clientdict(sid, clientdict)
357+
if session.clientdict != clientdict:
358+
logger.warning(
359+
"Requested operation has changed during the UI "
360+
"authentication session. A future version of Synapse "
361+
"will remove this capability."
362+
)
363+
364+
# For backwards compatibility, changes to the client dict are
365+
# persisted as clients modify them throughout their user interactive
366+
# authentication flow.
367+
await self.store.set_ui_auth_clientdict(sid, clientdict)
369368

370369
if not authdict:
371370
raise InteractiveAuthIncompleteError(

synapse/rest/client/v2_alpha/register.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ async def on_POST(self, request):
516516
body,
517517
self.hs.get_ip_from_request(request),
518518
"register a new account",
519-
validate_clientdict=False,
520519
)
521520

522521
# Check that we're not trying to register a denied 3pid.

synapse/storage/data_stores/main/roommember.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ def _get_joined_users_from_context(
566566
if key[0] == EventTypes.Member
567567
]
568568
for etype, state_key in context.delta_ids:
569-
users_in_room.pop(state_key, None)
569+
if etype == EventTypes.Member:
570+
users_in_room.pop(state_key, None)
570571

571572
# We check if we have any of the member event ids in the event cache
572573
# before we ask the DB

tests/rest/client/v2_alpha/test_auth.py

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -133,47 +133,6 @@ def test_fallback_captcha(self):
133133
# We're given a registered user.
134134
self.assertEqual(channel.json_body["user_id"], "@user:test")
135135

136-
def test_legacy_registration(self):
137-
"""
138-
Registration allows the parameters to vary through the process.
139-
"""
140-
141-
# Make the initial request to register. (Later on a different password
142-
# will be used.)
143-
# Returns a 401 as per the spec
144-
channel = self.register(
145-
401, {"username": "user", "type": "m.login.password", "password": "bar"},
146-
)
147-
148-
# Grab the session
149-
session = channel.json_body["session"]
150-
# Assert our configured public key is being given
151-
self.assertEqual(
152-
channel.json_body["params"]["m.login.recaptcha"]["public_key"], "brokencake"
153-
)
154-
155-
# Complete the recaptcha step.
156-
self.recaptcha(session, 200)
157-
158-
# also complete the dummy auth
159-
self.register(200, {"auth": {"session": session, "type": "m.login.dummy"}})
160-
161-
# Now we should have fulfilled a complete auth flow, including
162-
# the recaptcha fallback step. Make the initial request again, but
163-
# with a changed password. This still completes.
164-
channel = self.register(
165-
200,
166-
{
167-
"username": "user",
168-
"type": "m.login.password",
169-
"password": "foo", # Note that this is different.
170-
"auth": {"session": session},
171-
},
172-
)
173-
174-
# We're given a registered user.
175-
self.assertEqual(channel.json_body["user_id"], "@user:test")
176-
177136
def test_complete_operation_unknown_session(self):
178137
"""
179138
Attempting to mark an invalid session as complete should error.
@@ -282,9 +241,15 @@ def test_ui_auth(self):
282241
},
283242
)
284243

285-
def test_cannot_change_body(self):
244+
def test_can_change_body(self):
286245
"""
287-
The initial requested client dict cannot be modified during the user interactive authentication session.
246+
The client dict can be modified during the user interactive authentication session.
247+
248+
Note that it is not spec compliant to modify the client dict during a
249+
user interactive authentication session, but many clients currently do.
250+
251+
When Synapse is updated to be spec compliant, the call to re-use the
252+
session ID should be rejected.
288253
"""
289254
# Create a second login.
290255
self.login("test", self.user_pass)
@@ -302,9 +267,9 @@ def test_cannot_change_body(self):
302267
self.assertIn({"stages": ["m.login.password"]}, channel.json_body["flows"])
303268

304269
# Make another request providing the UI auth flow, but try to delete the
305-
# second device. This results in an error.
270+
# second device.
306271
self.delete_devices(
307-
403,
272+
200,
308273
{
309274
"devices": [device_ids[1]],
310275
"auth": {

tests/storage/test_roommember.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from synapse.types import Requester, UserID
2323

2424
from tests import unittest
25+
from tests.test_utils import event_injection
26+
from tests.utils import TestHomeServer
2527

2628

2729
class RoomMemberStoreTestCase(unittest.HomeserverTestCase):
@@ -38,7 +40,7 @@ def make_homeserver(self, reactor, clock):
3840
)
3941
return hs
4042

41-
def prepare(self, reactor, clock, hs):
43+
def prepare(self, reactor, clock, hs: TestHomeServer):
4244

4345
# We can't test the RoomMemberStore on its own without the other event
4446
# storage logic
@@ -114,6 +116,52 @@ def test_count_known_servers_stat_counter_enabled(self):
114116
# It now knows about Charlie's server.
115117
self.assertEqual(self.store._known_servers_count, 2)
116118

119+
def test_get_joined_users_from_context(self):
120+
room = self.helper.create_room_as(self.u_alice, tok=self.t_alice)
121+
bob_event = event_injection.inject_member_event(
122+
self.hs, room, self.u_bob, Membership.JOIN
123+
)
124+
125+
# first, create a regular event
126+
event, context = event_injection.create_event(
127+
self.hs,
128+
room_id=room,
129+
sender=self.u_alice,
130+
prev_event_ids=[bob_event.event_id],
131+
type="m.test.1",
132+
content={},
133+
)
134+
135+
users = self.get_success(
136+
self.store.get_joined_users_from_context(event, context)
137+
)
138+
self.assertEqual(users.keys(), {self.u_alice, self.u_bob})
139+
140+
# Regression test for #7376: create a state event whose key matches bob's
141+
# user_id, but which is *not* a membership event, and persist that; then check
142+
# that `get_joined_users_from_context` returns the correct users for the next event.
143+
non_member_event = event_injection.inject_event(
144+
self.hs,
145+
room_id=room,
146+
sender=self.u_bob,
147+
prev_event_ids=[bob_event.event_id],
148+
type="m.test.2",
149+
state_key=self.u_bob,
150+
content={},
151+
)
152+
event, context = event_injection.create_event(
153+
self.hs,
154+
room_id=room,
155+
sender=self.u_alice,
156+
prev_event_ids=[non_member_event.event_id],
157+
type="m.test.3",
158+
content={},
159+
)
160+
users = self.get_success(
161+
self.store.get_joined_users_from_context(event, context)
162+
)
163+
self.assertEqual(users.keys(), {self.u_alice, self.u_bob})
164+
117165

118166
class CurrentStateMembershipUpdateTestCase(unittest.HomeserverTestCase):
119167
def prepare(self, reactor, clock, homeserver):

0 commit comments

Comments
 (0)