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

Commit

Permalink
Handle review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 20, 2020
1 parent 7adeb25 commit afe0a36
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
26 changes: 9 additions & 17 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def validate_user_via_ui_auth(
requester: Requester,
request_body: Dict[str, Any],
clientip: str,
action_type,
action_id,
action_data,
):
"""
Checks that the user is who they claim to be, via a UI auth.
Expand All @@ -146,6 +145,9 @@ def validate_user_via_ui_auth(
clientip: The IP address of the client.
action_data: An opaque object that should be provided initially and at the
end to ensure the request is not modified during a session.
Returns:
defer.Deferred[dict]: the parameters for this request (which may
have been given only in a previous call).
Expand Down Expand Up @@ -178,7 +180,7 @@ def validate_user_via_ui_auth(

try:
result, params, _ = yield self.check_auth(
flows, request_body, clientip, action_type, action_id
flows, request_body, clientip, action_data
)
except LoginError:
# Update the ratelimite to say we failed (`can_do_action` doesn't raise).
Expand Down Expand Up @@ -222,8 +224,7 @@ def check_auth(
flows: List[List[str]],
clientdict: Dict[str, Any],
clientip: str,
action_type,
action_id,
action_data,
):
"""
Takes a dictionary sent by the client in the login / registration
Expand Down Expand Up @@ -292,14 +293,8 @@ def check_auth(
# If ui_auth exists in the session this is a returning UI auth request.
# Validate that none of the requested information has changed.
if "ui_auth" not in session:
session["ui_auth"] = {
"action_type": action_type,
"action_id": action_id,
}
elif (
session["ui_auth"]["action_type"] != action_type
or session["ui_auth"]["action_id"] != action_id
):
session["ui_auth"] = action_data
elif session["ui_auth"] != action_data:
raise SynapseError(403, "Foobar")

if not authdict:
Expand Down Expand Up @@ -529,10 +524,7 @@ def _invalidate_session(self, session_id) -> None:
if session and "ui_auth" in session:
# Set the items in the ui_auth session to sentinel values that can
# never be equaled.
session["ui_auth"] = {
"action_type": object(),
"action_id": object(),
}
session["ui_auth"] = object()

@defer.inlineCallbacks
def get_access_token_for_user_id(
Expand Down
14 changes: 7 additions & 7 deletions synapse/rest/client/v2_alpha/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ async def on_POST(self, request):
requester,
body,
self.hs.get_ip_from_request(request),
"modify_password",
"", # TODO
{"operation": "modify_password", "user": requester.user.to_string()},
)
user_id = requester.user.to_string()
else:
Expand All @@ -247,8 +246,7 @@ async def on_POST(self, request):
[[LoginType.EMAIL_IDENTITY]],
body,
self.hs.get_ip_from_request(request),
"modify_password",
"", # TODO
{"operation": "modify_password"}, # TODO
)

if LoginType.EMAIL_IDENTITY in result:
Expand Down Expand Up @@ -319,8 +317,7 @@ async def on_POST(self, request):
requester,
body,
self.hs.get_ip_from_request(request),
"deactivate",
requester.user.to_string(),
{"operation": "deactivate", "user": requester.user.to_string()},
)
result = await self._deactivate_account_handler.deactivate_account(
requester.user.to_string(), erase, id_server=body.get("id_server")
Expand Down Expand Up @@ -668,7 +665,10 @@ async def on_POST(self, request):
assert_valid_client_secret(client_secret)

await self.auth_handler.validate_user_via_ui_auth(
requester, body, self.hs.get_ip_from_request(request), "add_3pid", user_id
requester,
body,
self.hs.get_ip_from_request(request),
{"operation": "add_3pid", "user": user_id},
)

validation_session = await self.identity_handler.validate_threepid_session(
Expand Down
6 changes: 2 additions & 4 deletions synapse/rest/client/v2_alpha/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ async def on_POST(self, request):
requester,
body,
self.hs.get_ip_from_request(request),
"delete_devices",
"", # TODO
{"operation": "delete_devices", "devices": body["devices"]},
)

await self.device_handler.delete_devices(
Expand Down Expand Up @@ -134,8 +133,7 @@ async def on_DELETE(self, request, device_id):
requester,
body,
self.hs.get_ip_from_request(request),
"delete_device",
device_id,
{"operation": "delete_device", "device": device_id},
)

await self.device_handler.delete_device(requester.user.to_string(), device_id)
Expand Down
5 changes: 4 additions & 1 deletion synapse/rest/client/v2_alpha/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ async def on_POST(self, request):
body = parse_json_object_from_request(request)

await self.auth_handler.validate_user_via_ui_auth(
requester, body, self.hs.get_ip_from_request(request), "add_keys", user_id
requester,
body,
self.hs.get_ip_from_request(request),
{"operation": "add_keys", "user": user_id},
)

result = await self.e2e_keys_handler.upload_signing_keys_for_user(user_id, body)
Expand Down
3 changes: 1 addition & 2 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ async def on_POST(self, request):
self._registration_flows,
body,
self.hs.get_ip_from_request(request),
"register",
"", # TODO
{"operation": "register"},
)

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

0 comments on commit afe0a36

Please sign in to comment.