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

Add warning when /forget is used without a request body, as this is against the specification. #16365

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/16365.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add warning when `/forget` is used without a request body, as this is against the specification.
22 changes: 22 additions & 0 deletions synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
parse_enum,
parse_integer,
parse_json_object_from_request,
parse_json_value_from_request,
parse_string,
parse_strings_from_args,
)
Expand Down Expand Up @@ -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(
Expand All @@ -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
)
Expand Down
Loading