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

media admin list API breaks when some event contains invalid info in content #14536

@schmop

Description

@schmop

Description

You can send events containing non-spec conform contents like this:

{
    "content": {
        "url": "mxc://<server>/<media>",
        "info": null,
        "body": "<filename>",
        "msgtype": "m.image"
    },
    "type": "m.room.message"
}

The "List all media in a room" API processes it like this:

synapse/room.py at develop · matrix-org/synapse

[...]
                event_json = db_to_json(content_json)
                content = event_json["content"]
                content_url = content.get("url")
                thumbnail_url = content.get("info", {}).get("thumbnail_url")
[...]

That results in an error, seen below.

Steps to reproduce

  • Send non-spec-conforming image event containing "info": null in content
  • Send GET /_synapse/admin/v1/room/<room_id>/media
  • Receive error response with status code 500

Homeserver

another homeserver

Synapse Version

v1.71.0

Installation Method

Other (please mention below)

Database

Single PostgreSQL Server, never restored or migrated

Workers

Single process

Platform

Running in an FROM debian:bullseye-slim Container on a debian bullseye server.
Build from this repository from source.

Configuration

No response

Relevant log output

2022-11-23 14:03:47,276 - synapse.http.server - 124 - ERROR - GET-417 - Failed handle request via 'ListMediaInRoom': <XForwardedForRequest at 0x7f2d4044f160 method='GET' uri='/_synapse/admin/v1/room/<roomId>/media' clientproto='HTTP/1.1' site='8008'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/synapse/http/server.py", line 307, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "/usr/local/lib/python3.9/dist-packages/synapse/http/server.py", line 513, in _async_render
    callback_return = await raw_callback_return
  File "/usr/local/lib/python3.9/dist-packages/synapse/rest/admin/media.py", line 209, in on_GET
    local_mxcs, remote_mxcs = await self.store.get_media_mxcs_in_room(room_id)
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/databases/main/room.py", line 862, in get_media_mxcs_in_room
    return await self.db_pool.runInteraction(
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/database.py", line 881, in runInteraction
    return await delay_cancellation(_runInteraction())
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 1693, in _inlineCallbacks
    result = context.run(
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 518, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/database.py", line 848, in _runInteraction
    result = await self.runWithConnection(
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/database.py", line 976, in runWithConnection
    return await make_deferred_yieldable(
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/threadpool.py", line 244, in inContext
    result = inContext.theWork()  # type: ignore[attr-defined]
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/threadpool.py", line 260, in <lambda>
    inContext.theWork = lambda: context.call(  # type: ignore[attr-defined]
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/context.py", line 117, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/context.py", line 82, in callWithContext
    return func(*args, **kw)
  File "/usr/local/lib/python3.9/dist-packages/twisted/enterprise/adbapi.py", line 282, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/database.py", line 969, in inner_func
    return func(db_conn, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/database.py", line 710, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/databases/main/room.py", line 850, in _get_media_mxcs_in_room_txn
    local_mxcs, remote_mxcs = self._get_media_mxcs_in_room_txn(txn, room_id)
  File "/usr/local/lib/python3.9/dist-packages/synapse/storage/databases/main/room.py", line 916, in _get_media_mxcs_in_room_txn
    thumbnail_url = content.get("info", {}).get("thumbnail_url")
AttributeError: 'NoneType' object has no attribute 'get'

Anything else that would be useful to know?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Admin-APIA-Validation500 (mostly) errors due to lack of event/parameter validationO-UncommonMost users are unlikely to come across this or unexpected workflowS-MinorBlocks non-critical functionality, workarounds exist.T-DefectBugs, crashes, hangs, security vulnerabilities, or other reported issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions