-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure uploaded images are image files #9299
Conversation
8502760
to
0ba372f
Compare
# @param file request parameter for a file | ||
# @param | ||
def valid_image_file?(file, type = nil) | ||
ext = file.original_filename.split(".").last.downcase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, File.extname
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.extname
keeps the "."
.
When I changed the code over to that it ended up changing too much.
Deciding to keep it the way it was when I came in
d1858bb
to
7c15458
Compare
update:
update:
|
7c15458
to
1f65867
Compare
update:
|
file = fixture_file_upload('files/upload_image.txt', 'image/png') | ||
file = fixture_file_upload('spec/fixtures/test.txt.png') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, this was intentionally a .txt
file and not a .png
file (regardless of the guts of the file) to demonstrate neither .png nor .jpg.
So I'm wondering if this should be
file = fixture_file_upload('files/upload_image.txt', 'image/png') | |
file = fixture_file_upload('spec/fixtures/test.txt.png') | |
file = fixture_file_upload('spec/fixtures/test.txt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comment does makes a lot of sense.
But the upload_spec.rb
uses the name test.txt.png
to show that the controller is validating the file contents and not the file extension/mime type.
Before #8934 test.txt.png
incorrectly would work. Using that filename shows that we are validating the contents and not the filename itself.
This PR adds similar validation, so I think the new file with an image extension but contents that are not an image makes sense.
I did update this line to use the image mime-type.
introduce spec/fixtures with images of various image formats. Images of the name test.txt.png is a text file, but we tacked on the png suffix to ensure detection is correct. favicon.png.ico is a png, so we're using it to ensure proper detection on the server
Consolidated catalog uploads and icon uploads. Checking image magic numbers to ensure it is a png or jpg Resolves issue where user could upload a zip bomb
1f65867
to
6463af5
Compare
Skipping backport to |
Consolidated catalog uploads and icon uploads.
Checking image magic numbers to ensure it is a png or jpg
Resolves issue where user could upload a zip bomb
This only addresses
Tested with jpg, gif, png, and zip files