File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1+ Fix a bug introduced in 1.139.1 where a client could receive an Internal Server Error if they set `device_keys: null` in the request to [`POST /_matrix/client/v3/keys/upload`](https://spec.matrix.org/v1.16/client-server-api/#post_matrixclientv3keysupload).
Original file line number Diff line number Diff line change @@ -270,21 +270,21 @@ async def on_POST(
270270 400 , "To upload keys, you must pass device_id when authenticating"
271271 )
272272
273- if "device_keys" in body :
273+ if "device_keys" in body and isinstance ( body [ "device_keys" ], dict ) :
274274 # Validate the provided `user_id` and `device_id` fields in
275275 # `device_keys` match that of the requesting user. We can't do
276276 # this directly in the pydantic model as we don't have access
277277 # to the requester yet.
278278 #
279279 # TODO: We could use ValidationInfo when we switch to Pydantic v2.
280280 # https://docs.pydantic.dev/latest/concepts/validators/#validation-info
281- if body ["device_keys" ][ "user_id" ] != user_id :
281+ if body ["device_keys" ]. get ( "user_id" ) != user_id :
282282 raise SynapseError (
283283 code = HTTPStatus .BAD_REQUEST ,
284284 errcode = Codes .BAD_JSON ,
285285 msg = "Provided `user_id` in `device_keys` does not match that of the authenticated user" ,
286286 )
287- if body ["device_keys" ][ "device_id" ] != device_id :
287+ if body ["device_keys" ]. get ( "device_id" ) != device_id :
288288 raise SynapseError (
289289 code = HTTPStatus .BAD_REQUEST ,
290290 errcode = Codes .BAD_JSON ,
Original file line number Diff line number Diff line change @@ -160,6 +160,26 @@ def test_upload_keys_fails_on_invalid_user_id_or_device_id(self) -> None:
160160 channel .result ,
161161 )
162162
163+ def test_upload_keys_succeeds_when_fields_are_explicitly_set_to_null (self ) -> None :
164+ """
165+ This is a regression test for https://github.com/element-hq/synapse/pull/19023.
166+ """
167+ device_id = "DEVICE_ID"
168+ self .register_user ("alice" , "wonderland" )
169+ alice_token = self .login ("alice" , "wonderland" , device_id = device_id )
170+
171+ channel = self .make_request (
172+ "POST" ,
173+ "/_matrix/client/v3/keys/upload" ,
174+ {
175+ "device_keys" : None ,
176+ "one_time_keys" : None ,
177+ "fallback_keys" : None ,
178+ },
179+ alice_token ,
180+ )
181+ self .assertEqual (channel .code , HTTPStatus .OK , channel .result )
182+
163183
164184class KeyQueryTestCase (unittest .HomeserverTestCase ):
165185 servlets = [
You can’t perform that action at this time.
0 commit comments