-
Notifications
You must be signed in to change notification settings - Fork 5
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
Comment on ensuring that uploaded files are images #35
Comments
Thank you for the awesome feedback, as always! Because we are using We have tests for corrupted images and they seem to error out fine. If the user purposely tries to change the mimetype of their files and tries to upload a file and the LiveView fails, I wager that's intended behaviour. Although I do agree that it's best to cover all possible edge cases and properly show feedback to the user, is adding extra dependencies and making the time-to-predict slower worth it? What do you think? |
You can still upload the image (with a false MIME type) I believe. For simplicity (and quasi-completeness, fi possible),I would just use |
Yes, the person can still upload the image with false MIME type. What I'm saying is that if they are purposely tinkering with the mimetype and corrupting it on purpose, they deserve for the LiveView to fail :P. But I agree with you. I'll implement your piece of code once I'm through with #31 , unless you want to create a PR yourself 👍 |
Yes , the LV should send a warning that this task failed. I wait for your code to be ready and make a PR if you want once I digest your code :) For the test, probably a negative one is enough. Load a text file, change its MIME (to check), simulate the upload and capture the :error or flash. |
The code (as it stands) is ready. The PR I'm working on is just meant to compare Regarding the test, we already have one that checks if an invalid image is uploaded ->
Cheers for the feedback, btw, it's really appreciated! |
Closing since #37 was merged 🆗 |
About ensuring that uploaded files are images
The code below supposes that the user uploads isn't tricked in the sense that the declared MIME is not corrupted or disguised image files.
This maybe extra or unnecessary work at this stage to ensure that the uploaded file is indeed an image. The risks are to upload corrupted files into a bucket and to fail the Vix process.
However, in case of interest, I looked into this and believe we should/could use two consecutive strategies to ensure that the upload is a picture.
we firstly use libmagic via gen_magic. It works with magic numbers. It is added as a depency in the Dockerfile. We run this as a worker in order not to reload the C code on each call.
if this test is positive, we then run ExIamgeInfo to confirm by matching on the type of data. It does not use magic number but rather reads the content of the file. Note that this gives a
Sobelow
warning since we read external data.This should assure that we receive a file of type "image" with the desired format:
["webp", "jpeg", ""jpg"]
.Dependencies:
To get the idea on how to use this, the flow could be:
The text was updated successfully, but these errors were encountered: