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

Commit

Permalink
Validate input parameters for the sendToDevice API. (#8975)
Browse files Browse the repository at this point in the history
This makes the "messages" key in the content required. This is currently
optional in the spec, but that seems to be an error.
  • Loading branch information
clokep authored Dec 29, 2020
1 parent cfcf554 commit 14a7371
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/8975.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add validation to the `sendToDevice` API to raise a missing parameters error instead of a 500 error.
3 changes: 2 additions & 1 deletion synapse/rest/client/v2_alpha/sendtodevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Tuple

from synapse.http import servlet
from synapse.http.servlet import parse_json_object_from_request
from synapse.http.servlet import assert_params_in_dict, parse_json_object_from_request
from synapse.logging.opentracing import set_tag, trace
from synapse.rest.client.transactions import HttpTransactionCache

Expand Down Expand Up @@ -54,6 +54,7 @@ async def _put(self, request, message_type, txn_id):
requester = await self.auth.get_user_by_req(request, allow_guest=True)

content = parse_json_object_from_request(request)
assert_params_in_dict(content, ("messages",))

sender_user_id = requester.user.to_string()

Expand Down

0 comments on commit 14a7371

Please sign in to comment.