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.
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
Include file extension checks in attachment API #32151
Include file extension checks in attachment API #32151
Changes from all commits
35b44c2
d377e25
f9880a5
78ba2c0
864dc5a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
One problem with this implementation is that if we have the following conditions:
text/plain
is an allowed typeWe would return an
error
here, even though we may expect it not to (since stdlib treats empty files astext/plain
). Instead of changingVerify()
too much I could just create a separate func calledVerifyFileExtensionOnly()
.Then again, as I look at my example above, the logic in
Verify()
is interesting seeing that if you have a potential attachment with the following:... this would pass the verification checks. The current implementation does not follow this behavior and just checks if the filename is allowed.
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.
Currently I see a few approaches to this problem:
upload.Verify()
unchanged. But for subsequent edits to the attachment name verify that it uses an approved file extensionupload.Verify()
so that both the file extension and MIME type must be allowed in order for the attachment to be allowed. Any subsequent edits of the attachment name would have us verify that it uses an approved extension (i.e. it would be inline with the new behavior)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.
As far I can think of the third approach may suits best in this situation
becuase it will handle both MIME type and file extension .
it can be implemented something like this
.
.
.
please have a look into this implementation , let me hear your thoughts on this
thanks :)
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.
I think it's acceptable to not allow uploading empty file in reality.
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.
then it above fn will have a simple addon
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.
Yes, I believe it makes sense to disallow empty attachments.
My current problem is I am not sure if we should follow the way
Verify()
works when users try to edit attachment names. Since we don't seem to store the MIME types of attachments when they are uploaded, it doesn't seem possible currently. The current snapshot just checks the file extension when users try to do an edit.Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.