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

Commit 76f9c70

Browse files
authored
Always require users to re-authenticate for dangerous operations. (#10184)
Dangerous actions means deactivating an account, modifying an account password, or adding a 3PID. Other actions (deleting devices, uploading keys) can re-use the same UI auth session if ui_auth.session_timeout is configured.
1 parent b8b282a commit 76f9c70

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

changelog.d/10184.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always require users to re-authenticate for dangerous operations: deactivating an account, modifying an account password, and adding 3PIDs.

docs/sample_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,6 +2318,10 @@ ui_auth:
23182318
# the user-interactive authentication process, by allowing for multiple
23192319
# (and potentially different) operations to use the same validation session.
23202320
#
2321+
# This is ignored for potentially "dangerous" operations (including
2322+
# deactivating an account, modifying an account password, and
2323+
# adding a 3PID).
2324+
#
23212325
# Uncomment below to allow for credential validation to last for 15
23222326
# seconds.
23232327
#

synapse/config/auth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
103103
# the user-interactive authentication process, by allowing for multiple
104104
# (and potentially different) operations to use the same validation session.
105105
#
106+
# This is ignored for potentially "dangerous" operations (including
107+
# deactivating an account, modifying an account password, and
108+
# adding a 3PID).
109+
#
106110
# Uncomment below to allow for credential validation to last for 15
107111
# seconds.
108112
#

synapse/handlers/auth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ async def validate_user_via_ui_auth(
302302
request: SynapseRequest,
303303
request_body: Dict[str, Any],
304304
description: str,
305+
can_skip_ui_auth: bool = False,
305306
) -> Tuple[dict, Optional[str]]:
306307
"""
307308
Checks that the user is who they claim to be, via a UI auth.
@@ -320,6 +321,10 @@ async def validate_user_via_ui_auth(
320321
description: A human readable string to be displayed to the user that
321322
describes the operation happening on their account.
322323
324+
can_skip_ui_auth: True if the UI auth session timeout applies this
325+
action. Should be set to False for any "dangerous"
326+
actions (e.g. deactivating an account).
327+
323328
Returns:
324329
A tuple of (params, session_id).
325330
@@ -343,7 +348,7 @@ async def validate_user_via_ui_auth(
343348
"""
344349
if not requester.access_token_id:
345350
raise ValueError("Cannot validate a user without an access token")
346-
if self._ui_auth_session_timeout:
351+
if can_skip_ui_auth and self._ui_auth_session_timeout:
347352
last_validated = await self.store.get_access_token_last_validated(
348353
requester.access_token_id
349354
)

synapse/rest/client/v2_alpha/devices.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ async def on_POST(self, request):
8686
request,
8787
body,
8888
"remove device(s) from your account",
89+
# Users might call this multiple times in a row while cleaning up
90+
# devices, allow a single UI auth session to be re-used.
91+
can_skip_ui_auth=True,
8992
)
9093

9194
await self.device_handler.delete_devices(
@@ -135,6 +138,9 @@ async def on_DELETE(self, request, device_id):
135138
request,
136139
body,
137140
"remove a device from your account",
141+
# Users might call this multiple times in a row while cleaning up
142+
# devices, allow a single UI auth session to be re-used.
143+
can_skip_ui_auth=True,
138144
)
139145

140146
await self.device_handler.delete_device(requester.user.to_string(), device_id)

synapse/rest/client/v2_alpha/keys.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ async def on_POST(self, request):
277277
request,
278278
body,
279279
"add a device signing key to your account",
280+
# Allow skipping of UI auth since this is frequently called directly
281+
# after login and it is silly to ask users to re-auth immediately.
282+
can_skip_ui_auth=True,
280283
)
281284

282285
result = await self.e2e_keys_handler.upload_signing_keys_for_user(user_id, body)

0 commit comments

Comments
 (0)