Skip to content

Conversation

@LaurenceJJones
Copy link
Contributor

Restrict File Upload Types

Summary

Adds file type restriction to the application image upload input using the accept attribute to improve user experience and prevent invalid file selections.

Changes

  • Added accept="image/png,image/jpeg,image/gif" attribute to the file input element in Applications.tsx

Benefits

  • Better UX: File picker now defaults to showing only supported image types (PNG, JPEG, GIF)
  • Reduces errors: Users are less likely to select unsupported file types
  • Prevents confusion: No need to manually filter through all file types

Technical Details

  • The accept attribute provides a hint to the browser's file picker to filter files
  • Existing validation logic remains in place as a fallback for edge cases
  • Backward compatible - no breaking changes

Testing

  • Verify file picker shows only image files on click
  • Confirm validation still works if invalid file type is selected (edge case)
  • Test on multiple browsers (Chrome, Firefox, Safari)

@LaurenceJJones LaurenceJJones requested a review from a team as a code owner November 5, 2025 16:52
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.14%. Comparing base (f263221) to head (ca20541).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@eternal-flame-AD eternal-flame-AD left a 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)?

server/api/application.go

Lines 461 to 468 in f263221

func ValidApplicationImageExt(ext string) bool {
switch ext {
case ".gif", ".png", ".jpg", ".jpeg":
return true
default:
return false
}
}

image

@eternal-flame-AD
Copy link
Member

It seems just put the extension explicitly would be great.

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file#unique_file_type_specifiers

@LaurenceJJones
Copy link
Contributor Author

LaurenceJJones commented Nov 5, 2025

Should we also update the pre check here as it based on mime

if (['image/png', 'image/jpeg', 'image/gif'].indexOf(file.type) !== -1) {
appStore.uploadImage(uploadId.current, file);
} else {

- Validate file extension (.gif, .png, .jpg, .jpeg) to match backend
- Also validate MIME type for defense in depth
- Reuse validExtensions array for accept attribute
@eternal-flame-AD
Copy link
Member

eternal-flame-AD commented Nov 5, 2025

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.

@eternal-flame-AD
Copy link
Member

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!

@eternal-flame-AD eternal-flame-AD force-pushed the restrict-file-upload-types branch from c42dd47 to 324ff1a Compare November 5, 2025 20:33
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
@eternal-flame-AD eternal-flame-AD force-pushed the restrict-file-upload-types branch from 324ff1a to ca20541 Compare November 5, 2025 20:34
@eternal-flame-AD eternal-flame-AD merged commit 71e38b9 into gotify:master Nov 5, 2025
3 checks passed
@LaurenceJJones LaurenceJJones deleted the restrict-file-upload-types branch November 7, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants