diff --git a/changelog.d/17864.misc b/changelog.d/17864.misc new file mode 100644 index 0000000000..3402bc2582 --- /dev/null +++ b/changelog.d/17864.misc @@ -0,0 +1 @@ +Prevent exception from receiving an invalid `Content-Type` response header upon fetching remote media. \ No newline at end of file diff --git a/synapse/media/media_repository.py b/synapse/media/media_repository.py index 859b30e029..22ae545acd 100644 --- a/synapse/media/media_repository.py +++ b/synapse/media/media_repository.py @@ -961,7 +961,11 @@ class MediaRepository: ) raise SynapseError(502, "Failed to fetch remote media") - if b"Content-Type" in headers: + if ( + b"Content-Type" in headers + and len(headers[b"Content-Type"]) > 0 + and headers[b"Content-Type"][0] is not None + ): media_type = headers[b"Content-Type"][0].decode("ascii") else: media_type = "application/octet-stream"