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

Add the ability to restrict max avatar filesize and content-type #19

Merged
merged 15 commits into from
Dec 12, 2019

Conversation

anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Dec 5, 2019

Add an option to prevent users from changing their avatar to something that's greater than a maximum size and/or is not a within a whitelist of file mimetypes.

@anoadragon453 anoadragon453 self-assigned this Dec 5, 2019
@anoadragon453
Copy link
Member Author

Sytests are failing until sytest-synapse:dinsic docker is fixed.

synapse/handlers/profile.py Outdated Show resolved Hide resolved
synapse/handlers/profile.py Outdated Show resolved Hide resolved
synapse/rest/client/v1/profile.py Outdated Show resolved Hide resolved
synapse/rest/client/v1/profile.py Outdated Show resolved Hide resolved
Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some tidying up really, nothing major.

):
# Parse the media URI
try:
media_id = new_avatar_url.split("/")[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never actually throws btw, since .split will always return at least one thing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is what I was looking for with the ValueError:

            try:
                _, media_id = new_avatar_url.split("/")
            except ValueError:
                raise SynapseError(400, "Invalid avatar URL '%s' supplied" %
                                   new_avatar_url)

synapse/rest/media/v1/media_repository.py Outdated Show resolved Hide resolved
#
# Note that this only applies to when an avatar is changed globally.
# Per-room avatar changes are not affected. See allow_per_room_profiles
# for disabling that functionality.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this OK for dinsic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They currently have per-room avatar functionality disabled, thus all avatar changes must be made globally, which the new option will gatekeep.

synapse/handlers/profile.py Outdated Show resolved Hide resolved
synapse/handlers/profile.py Outdated Show resolved Hide resolved
@anoadragon453 anoadragon453 requested review from erikjohnston and removed request for erikjohnston December 11, 2019 17:42
@anoadragon453 anoadragon453 merged commit f4d1ab0 into dinsic Dec 12, 2019
@anoadragon453 anoadragon453 deleted the anoa/media_store_limits branch December 12, 2019 13:51
babolivier added a commit to matrix-org/synapse that referenced this pull request Jan 28, 2022
Only allow files which file size and content types match configured
limits to be set as avatar.

Most of the inspiration from the non-test code comes from matrix-org/synapse-dinsic#19
babolivier added a commit that referenced this pull request Jan 28, 2022
Only allow files which file size and content types match configured
limits to be set as avatar.

Most of the inspiration from the non-test code comes from #19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants