From da19c6fcf7d6b8f416f466ac102e2742937baa63 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 22 Sep 2023 18:59:10 +0100 Subject: [PATCH 1/2] Add warnings when /forget isn't given a JSON body --- synapse/rest/client/room.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py index 553938ce9d13..8ca22c799150 100644 --- a/synapse/rest/client/room.py +++ b/synapse/rest/client/room.py @@ -47,6 +47,7 @@ parse_enum, parse_integer, parse_json_object_from_request, + parse_json_value_from_request, parse_string, parse_strings_from_args, ) @@ -960,6 +961,17 @@ async def on_POST( self, request: SynapseRequest, room_id: str ) -> Tuple[int, JsonDict]: requester = await self.auth.get_user_by_req(request, allow_guest=False) + + content = parse_json_value_from_request(request, allow_empty_body=True) + if content is None: + logger.warning( + "No JSON body supplied to POST /forget. " + "This is not spec-compliant and will not be accepted in a future release!" + ) + elif not isinstance(content, dict): + message = "Content must be a JSON object." + raise SynapseError(HTTPStatus.BAD_REQUEST, message, errcode=Codes.BAD_JSON) + return await self._do(requester, room_id) async def on_PUT( @@ -968,6 +980,16 @@ async def on_PUT( requester = await self.auth.get_user_by_req(request, allow_guest=False) set_tag("txn_id", txn_id) + content = parse_json_value_from_request(request, allow_empty_body=True) + if content is None: + logger.warning( + "No JSON body supplied to PUT /forget. " + "This is not spec-compliant and will not be accepted in a future release!" + ) + elif not isinstance(content, dict): + message = "Content must be a JSON object." + raise SynapseError(HTTPStatus.BAD_REQUEST, message, errcode=Codes.BAD_JSON) + return await self.txns.fetch_or_execute_request( request, requester, self._do, requester, room_id ) From 0cfe2af408d13c446ca59f17956ae7e814d864d6 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 22 Sep 2023 19:00:28 +0100 Subject: [PATCH 2/2] Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) --- changelog.d/16365.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/16365.misc diff --git a/changelog.d/16365.misc b/changelog.d/16365.misc new file mode 100644 index 000000000000..f423d4dd9897 --- /dev/null +++ b/changelog.d/16365.misc @@ -0,0 +1 @@ +Add warning when `/forget` is used without a request body, as this is against the specification. \ No newline at end of file