Use storage classes to manipulate image uploads#25007
Open
diox wants to merge 3 commits into
Open
Conversation
Also remove outdated migrate_user_photos code
eviljeff
approved these changes
Jun 9, 2026
| # Keep a copy of the original image. This might not be the right | ||
| # extension as it hasn't been converted into a different format. | ||
| dest_file = addon.get_icon_path('original') | ||
| if source != dest_file: |
Member
There was a problem hiding this comment.
Can source ever be == to dest_file? I.e. is it a redundant if condition? (similarly below in resize_preview)
Member
Author
There was a problem hiding this comment.
Yes - in fact I realized writing this patch that there is a slight difference between how devhub and the API works here: devhub saves a temporary file path which is passed to the resize_preview/ resize_icon task, where as the API directly saves the file to the original path and calls the task with that "original" path - removing the need for the extra move/rename.
That's something we might want to look into later, but I didn't want to change that here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes mozilla/addons#16060
Context
Back in 5699608 we started validating
upload_hashto prevent potential path traversal issues. This adds an additional more robust layer of protection by avoidingos.*operations and making sure we use storage with the appropriate root when uploading images.Drive-by
migrate_user_photoscommandacceptattribute to icon & previews upload flow (I kept uploading icons & previews over and over again and was tired of seeing files that are not valid in the file browser)Testing
icon_hashadded in 5699608upload_icon_hashhidden input. Itsvalueattribute should be a hash.value, setting it to../../../../storage/.../path/that/exists. For instance, if you have an avatar for your user withid=1, try../../../../storage/shared_storage/uploads/userpics/01/0001/1/1.pngDEBUG=True, you should see the response for that 400 should be aSuspiciousFileOperationerror.