-
-
Notifications
You must be signed in to change notification settings - Fork 800
Add file type restriction to image upload input using accept attribute #872
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
Add file type restriction to image upload input using accept attribute #872
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #872 +/- ##
=======================================
Coverage 79.14% 79.14%
=======================================
Files 56 56
Lines 2225 2225
=======================================
Hits 1761 1761
Misses 360 360
Partials 104 104 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eternal-flame-AD
left a comment
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.
Thanks, it works.
It seems like there are a couple additional extensions that would not have been accepted by ValidApplicationImageExt function, could you align it with the code (which accepted by extension not broad MIME type alignment)?
Lines 461 to 468 in f263221
| func ValidApplicationImageExt(ext string) bool { | |
| switch ext { | |
| case ".gif", ".png", ".jpg", ".jpeg": | |
| return true | |
| default: | |
| return false | |
| } | |
| } |
|
It seems just put the extension explicitly would be great. |
|
Should we also update the pre check here as it based on mime server/ui/src/application/Applications.tsx Lines 74 to 76 in f263221
|
- Validate file extension (.gif, .png, .jpg, .jpeg) to match backend - Also validate MIME type for defense in depth - Reuse validExtensions array for accept attribute
|
Hmm, honestly if it catches error early enough I would say good enough. I might even say the additional MIME checks are redundant (afaik they don't check the file contents? It's just a static mapping based on extension). It seems the server side check is the strictest, as long as it isn't stricter than that I would say LGTM. |
|
I think I can take it over from now, I will do a cross platform test later today and if needed I will just push directly. Thanks for the PR! |
c42dd47 to
324ff1a
Compare
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
324ff1a to
ca20541
Compare
Restrict File Upload Types
Summary
Adds file type restriction to the application image upload input using the
acceptattribute to improve user experience and prevent invalid file selections.Changes
accept="image/png,image/jpeg,image/gif"attribute to the file input element inApplications.tsxBenefits
Technical Details
acceptattribute provides a hint to the browser's file picker to filter filesTesting