matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.82k stars 2.13k forks source link

Internal server error when deleting a room with the Admin API with invalid `new_room_user_id` #13630

Open atuctuc opened 2 years ago

atuctuc commented 2 years ago

hallo i want to delete rooms on my server with this command. unfortunately i always get this error.

curl -XDELETE "https://my.spdns.org/_synapse/admin/v2/rooms/$room_id" \                                    
-H "Authorization: Bearer $TOKEN" \       
-d'{"new_room_user_id": "", "message": "This room has been removed", "room_name": "", "block": true, "purge": true }'                                                                    
{"errcode":"M_UNKNOWN","error":"Internal server error"}

my synapse shows the following in the log file:

2022-08-25 17:43:26,232 - synapse.http.server - 185 - ERROR - DELETE-182 - Failed handle request via 'RoomRestV2Servlet': <XForwardedForRequest at 0x7f6bf7487f40 method='DELETE' uri='/_synapse/admin/v2/rooms/!BMsScQstcoyurcWVxK:my.spdns.org' clientproto='HTTP/1.0' site='8008'>
Traceback (most recent call last):
  File "/home/alex/synapse/env/lib/python3.9/site-packages/twisted/internet/defer.py", line 1660, in _inlineCallbacks
    result = current_context.run(gen.send, result)
StopIteration: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/synapse/env/lib/python3.9/site-packages/synapse/http/server.py", line 368, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "/home/alex/synapse/env/lib/python3.9/site-packages/synapse/http/server.py", line 574, in _async_render
    callback_return = await raw_callback_return
  File "/home/alex/synapse/env/lib/python3.9/site-packages/synapse/rest/admin/rooms.py", line 119, in on_DELETE
    delete_id = self._pagination_handler.start_shutdown_and_purge_room(
  File "/home/alex/synapse/env/lib/python3.9/site-packages/synapse/handlers/pagination.py", line 751, in start_shutdown_and_purge_room
    if not self.hs.is_mine_id(new_room_user_id):
  File "/home/alex/synapse/env/lib/python3.9/site-packages/synapse/server.py", line 343, in is_mine_id
    return string.split(":", 1)[1] == self.hostname
IndexError: list index out of range

any idea whats wrong? thanks anan

DMRobertson commented 2 years ago

@atuctuc To delete a room without providing a replacement, omit "new_room_user_id" from the request body. (see also https://matrix-org.github.io/synapse/latest/admin_api/rooms.html: "optional" fields should be omitted rather than empty strings).

You probably want to use

curl -XDELETE "https://my.spdns.org/_synapse/admin/v2/rooms/$room_id" \                                    
-H "Authorization: Bearer $TOKEN" \       
-d'{"message": "This room has been removed", "block": true, "purge": true }'
DMRobertson commented 2 years ago

Synapse would ideally validate that new_room_user_id is a valid user ID (if provided) and give a reasonable error message if it's invalid.

atuctuc commented 2 years ago

ah, thanks, ist works now!!