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
Fix to verify pdf file type and limit pdf size #1785
Merged
tompollard
merged 4 commits into
MIT-LCP:dev
from
T-CAIREM:fix/arbitary_file_upload_in_training_v3
Jan 6, 2023
Merged
Fix to verify pdf file type and limit pdf size #1785
tompollard
merged 4 commits into
MIT-LCP:dev
from
T-CAIREM:fix/arbitary_file_upload_in_training_v3
Jan 6, 2023
Conversation
This file contains 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
1. Added a utility function to verify if the uploaded file is a pdf file or not. Currently users are able to upload any file type by changing the file extension in the training form. This commit adds a utility function to verify if the uploaded file is a pdf file or not. 2. Update test to work with the training pdf validation The new change makes sure that the file uploaded is a valid pdf and is readable. Our previous test was using django core SimpleUploadedFile to create a plain/txt file and uploading that which is not a valid pdf(even if we change the content type). So the solution to this would be to either create pdf on the fly during the test or use a static valid pdf file. I chose the later option, because creating pdf on the fly would require us to add a new dependency to the project which might introduce a security risk and need more discussion. 3. Added a file size limit for pdf Also, earlier there was no limit on the file size, i added a limit of 1MB Default(but customizable from .env) for the pdf file For the file size validation function, i added it in the user.validators instead of adding it somewhere else like physionet.utility because, i thought we might to implement different sizes for different applications, so i didnot try to make it generic.
tompollard
reviewed
Jan 6, 2023
1. In previous commit, i had forgotten to change the variable name for the size upload limit(we wanted to use the file size limit in KB, i had made changes for that, but forgot to make change in the function) 2. Also there was an mistake where the size limit has hardcoded as 5MB, so we updated the code to show the actual limit as per .env setup in KB
amitupreti
force-pushed
the
fix/arbitary_file_upload_in_training_v3
branch
from
January 6, 2023 15:45
b072d1b
to
2b0b8d4
Compare
tompollard
reviewed
Jan 6, 2023
…e forget to set the size limit on env file
tompollard
reviewed
Jan 6, 2023
Thanks @amitupreti, looks good to me! |
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.
Added a utility function to verify if the uploaded file is a pdf file or not.
Currently users are able to upload any file type by changing the file extension in the training form.
This commit adds a utility function to verify if the uploaded file is a pdf file or not.
Update test to work with the training pdf validation The new change makes sure that the file uploaded is a valid pdf and is readable. Our previous test was using django core SimpleUploadedFile to create a plain/txt file and uploading that which is not a valid pdf(even if we change the content type). So the solution to this would be to either create pdf on the fly during the test or use a static valid pdf file.
I chose the later option, because creating pdf on the fly would require us to add a new dependency to the project which might introduce a security risk and need more discussion.
Added a file size limit for pdf Also, earlier there was no limit on the file size, i added a limit of 1MB Default(but customizable from .env) for the pdf file For the file size validation function, i added it in the user.validators instead of adding it somewhere else like physionet.utility because, i thought we might to implement different sizes for different applications, so i didnot try to make it generic.