This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate device_keys for C-S /keys/query requests (#10593)
* Validate device_keys for C-S /keys/query requests Closes #10354 A small, not particularly critical fix. I'm interested in seeing if we can find a more systematic approach though. #8445 is the place for any discussion.
- Loading branch information
David Robertson
authored
Aug 20, 2021
1 parent
e81d620
commit ee3b2ac
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reject Client-Server /keys/query requests which provide device_ids incorrectly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from http import HTTPStatus | ||
|
||
from synapse.api.errors import Codes | ||
from synapse.rest import admin | ||
from synapse.rest.client import keys, login | ||
|
||
from tests import unittest | ||
|
||
|
||
class KeyQueryTestCase(unittest.HomeserverTestCase): | ||
servlets = [ | ||
keys.register_servlets, | ||
admin.register_servlets_for_client_rest_resource, | ||
login.register_servlets, | ||
] | ||
|
||
def test_rejects_device_id_ice_key_outside_of_list(self): | ||
self.register_user("alice", "wonderland") | ||
alice_token = self.login("alice", "wonderland") | ||
bob = self.register_user("bob", "uncle") | ||
channel = self.make_request( | ||
"POST", | ||
"/_matrix/client/r0/keys/query", | ||
{ | ||
"device_keys": { | ||
bob: "device_id1", | ||
}, | ||
}, | ||
alice_token, | ||
) | ||
self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result) | ||
self.assertEqual( | ||
channel.json_body["errcode"], | ||
Codes.BAD_JSON, | ||
channel.result, | ||
) | ||
|
||
def test_rejects_device_key_given_as_map_to_bool(self): | ||
self.register_user("alice", "wonderland") | ||
alice_token = self.login("alice", "wonderland") | ||
bob = self.register_user("bob", "uncle") | ||
channel = self.make_request( | ||
"POST", | ||
"/_matrix/client/r0/keys/query", | ||
{ | ||
"device_keys": { | ||
bob: { | ||
"device_id1": True, | ||
}, | ||
}, | ||
}, | ||
alice_token, | ||
) | ||
|
||
self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result) | ||
self.assertEqual( | ||
channel.json_body["errcode"], | ||
Codes.BAD_JSON, | ||
channel.result, | ||
) | ||
|
||
def test_requires_device_key(self): | ||
"""`device_keys` is required. We should complain if it's missing.""" | ||
self.register_user("alice", "wonderland") | ||
alice_token = self.login("alice", "wonderland") | ||
channel = self.make_request( | ||
"POST", | ||
"/_matrix/client/r0/keys/query", | ||
{}, | ||
alice_token, | ||
) | ||
self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result) | ||
self.assertEqual( | ||
channel.json_body["errcode"], | ||
Codes.BAD_JSON, | ||
channel.result, | ||
) |