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

Commit

Permalink
Switch to using an allow list for URL previewable content types.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkasak committed Feb 10, 2022
1 parent 65dd4f1 commit 2f3bb1f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ async def _download_url(self, url: str, output_stream: BinaryIO) -> DownloadResu
output_stream=output_stream,
max_size=self.max_spider_size,
headers={"Accept-Language": self.url_preview_accept_language},
is_allowed_content_type=_is_not_av_media,
is_allowed_content_type=_is_previewable,
)
except SynapseError:
# Pass SynapseErrors through directly, so that the servlet
Expand Down Expand Up @@ -764,9 +764,14 @@ def _is_json(content_type: str) -> bool:
return content_type.lower().startswith("application/json")


def _is_not_av_media(content_type: bytes) -> bool:
"""Returns False if the content type is audio or video."""
def _is_previewable(content_type: bytes) -> bool:
"""Returns True for content types for which we will perform URL preview and False
otherwise."""

content_type = content_type.lower()
return not content_type.startswith(b"video/") and not content_type.startswith(
b"audio/"
return (
content_type.startswith(b"text/html")
or content_type.startswith(b"application/xhtml")
or content_type.startswith(b"image/")
or content_type.startswith(b"application/json")
)

0 comments on commit 2f3bb1f

Please sign in to comment.