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

Only allow skipping UI auth for certain actions. #10184

Merged
merged 4 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10184.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Always require users to re-authenticate for dangerous operations: deactivating an account, modifying an account password, and adding 3PIDs.
4 changes: 4 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,10 @@ ui_auth:
# the user-interactive authentication process, by allowing for multiple
# (and potentially different) operations to use the same validation session.
#
# This is ignored for potentially "dangerous" operations (including
# deactivating an account, modifying an account password, and
# adding a 3PID).
#
# Uncomment below to allow for credential validation to last for 15
# seconds.
#
Expand Down
4 changes: 4 additions & 0 deletions synapse/config/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# the user-interactive authentication process, by allowing for multiple
# (and potentially different) operations to use the same validation session.
#
# This is ignored for potentially "dangerous" operations (including
# deactivating an account, modifying an account password, and
# adding a 3PID).
#
# Uncomment below to allow for credential validation to last for 15
# seconds.
#
Expand Down
7 changes: 6 additions & 1 deletion synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ async def validate_user_via_ui_auth(
request: SynapseRequest,
request_body: Dict[str, Any],
description: str,
can_skip_ui_auth: bool = False,
) -> Tuple[dict, Optional[str]]:
"""
Checks that the user is who they claim to be, via a UI auth.
Expand All @@ -320,6 +321,10 @@ async def validate_user_via_ui_auth(
description: A human readable string to be displayed to the user that
describes the operation happening on their account.

can_skip_ui_auth: True if the UI auth session timeout applies this
action. Should be set to False for any "dangerous"
actions (e.g. deactivating an account).

Returns:
A tuple of (params, session_id).

Expand All @@ -343,7 +348,7 @@ async def validate_user_via_ui_auth(
"""
if not requester.access_token_id:
raise ValueError("Cannot validate a user without an access token")
if self._ui_auth_session_timeout:
if can_skip_ui_auth and self._ui_auth_session_timeout:
last_validated = await self.store.get_access_token_last_validated(
requester.access_token_id
)
Expand Down
6 changes: 6 additions & 0 deletions synapse/rest/client/v2_alpha/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ async def on_POST(self, request):
request,
body,
"remove device(s) from your account",
# Users might call this multiple times in a row while cleaning up
# devices, allow a single UI auth session to be re-used.
can_skip_ui_auth=True,
)

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

await self.device_handler.delete_device(requester.user.to_string(), device_id)
Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/client/v2_alpha/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ async def on_POST(self, request):
request,
body,
"add a device signing key to your account",
# Allow skipping of UI auth since this is frequently called directly
# after login and it is silly to ask users to re-auth immediately.
can_skip_ui_auth=True,
)

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