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

Commit 5d64fef

Browse files
authored
Do not validate that the client dict is stable during UI Auth. (#7483)
This backs out some of the validation for the client dictionary and logs if this changes during a user interactive authentication session instead.
1 parent edd3b07 commit 5d64fef

File tree

4 files changed

+29
-65
lines changed

4 files changed

+29
-65
lines changed

changelog.d/7483.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore compatibility with non-compliant clients during the user interactive authentication process.

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.

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": {

0 commit comments

Comments
 (0)