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

Commit

Permalink
Merge pull request #2591 from matrix-org/rav/device_delete_auth
Browse files Browse the repository at this point in the history
Device deletion: check UI auth matches access token
  • Loading branch information
richvdh authored Oct 27, 2017
2 parents 110b373 + 7a65462 commit 4d83632
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions synapse/rest/client/v2_alpha/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def on_GET(self, request, device_id):

@defer.inlineCallbacks
def on_DELETE(self, request, device_id):
requester = yield self.auth.get_user_by_req(request)

try:
body = servlet.parse_json_object_from_request(request)

Expand All @@ -135,11 +137,12 @@ def on_DELETE(self, request, device_id):
if not authed:
defer.returnValue((401, result))

requester = yield self.auth.get_user_by_req(request)
yield self.device_handler.delete_device(
requester.user.to_string(),
device_id,
)
# check that the UI auth matched the access token
user_id = result[constants.LoginType.PASSWORD]
if user_id != requester.user.to_string():
raise errors.AuthError(403, "Invalid auth")

yield self.device_handler.delete_device(user_id, device_id)
defer.returnValue((200, {}))

@defer.inlineCallbacks
Expand Down

0 comments on commit 4d83632

Please sign in to comment.