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

Discard empty upload_name before persisting file #7905

Merged
merged 14 commits into from
Sep 29, 2020
1 change: 1 addition & 0 deletions changelog.d/7905.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix synapse storing a media file with an invalid media_type or upload_name.
12 changes: 11 additions & 1 deletion synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from twisted.web.resource import Resource

from synapse.api.errors import (
Codes,
FederationDeniedError,
HttpResponseException,
NotFoundError,
Expand Down Expand Up @@ -141,14 +142,23 @@ async def create_content(

Args:
media_type(str): The content type of the file
clokep marked this conversation as resolved.
Show resolved Hide resolved
upload_name(str): The name of the file
upload_name(str|None): The name of the file
clokep marked this conversation as resolved.
Show resolved Hide resolved
content: A file like object that is the content to store
content_length(int): The length of the content
auth_user(str): The user_id of the uploader

Returns:
Deferred[str]: The mxc url of the stored content
"""

if not isinstance(media_type, str):
raise SynapseError(400, "Invalid parameter media_type", Codes.INVALID_PARAM)

if upload_name and not isinstance(upload_name, str):
raise SynapseError(
400, "Invalid parameter upload_name", Codes.INVALID_PARAM
)

media_id = random_string(24)

file_info = FileInfo(server_name=None, file_id=media_id)
Expand Down