Skip to content

Commit ea48c2b

Browse files
committed
fix: Conditionally allow for ignoring unknown media for profile avatars when propagating membership events
Borrow the experimental setting that disables legacy media uploads
1 parent 0ad7963 commit ea48c2b

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

synapse/handlers/room_member.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def __init__(self, hs: "HomeServer"):
110110
self.event_auth_handler = hs.get_event_auth_handler()
111111
self._worker_lock_handler = hs.get_worker_locks_handler()
112112
self.enable_restricted_media = hs.config.experimental.msc3911_enabled
113+
# This is technically wrong, but works for proof of concept
114+
self.allow_legacy_media = not hs.config.experimental.msc3911_unrestricted_media_upload_disabled
113115

114116
self._membership_types_to_include_profile_data_in = {
115117
Membership.JOIN,
@@ -869,15 +871,24 @@ async def update_membership_locked(
869871
# Something about the MediaRepository does not like being part of
870872
# the initialization code of the RoomMemberHandler, so just import
871873
# it on the spot instead.
872-
media_repo = self.hs.get_media_repository()
874+
media_repo = self.hs.get_media_repository() #
873875

874-
new_mxc_uri = await media_repo.copy_media(
875-
MXCUri.from_str(avatar_url), requester.user, 20_000
876-
)
877-
media_object = await media_repo.get_media_info(new_mxc_uri)
878-
assert isinstance(media_object, LocalMedia)
879-
media_info_for_attachment = {media_object}
880-
content[EventContentFields.MEMBERSHIP_AVATAR_URL] = str(new_mxc_uri)
876+
try:
877+
new_mxc_uri = await media_repo.copy_media(
878+
MXCUri.from_str(avatar_url), requester.user, 20_000
879+
)
880+
except SynapseError:
881+
# The copy command can fail if the media doesn't already exist.
882+
# In this case, if legacy media is allowed, ignore it. Otherwise, deny it and re-raise
883+
if self.allow_legacy_media:
884+
pass
885+
else:
886+
raise
887+
else:
888+
media_object = await media_repo.get_media_info(new_mxc_uri)
889+
assert isinstance(media_object, LocalMedia)
890+
media_info_for_attachment = {media_object}
891+
content[EventContentFields.MEMBERSHIP_AVATAR_URL] = str(new_mxc_uri)
881892

882893
# if this is a join with a 3pid signature, we may need to turn a 3pid
883894
# invite into a normal invite before we can handle the join.

0 commit comments

Comments
 (0)