Fix file validation and add upload progress UI (#142)#173
Open
uv05709 wants to merge 9 commits into
Open
Conversation
Contributor
|
@uv05709 is attempting to deploy a commit to the Sameer's projects Team on Vercel. A member of the Team first needs to authorize it. |
…05709/NPMChat into fix/issue-142-file-validation
Contributor
Author
|
@ThePlator merge my PR |
This file contains hidden or 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
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.
Fix: Secure File Upload Validation + Progress UI + Upload Cancellation
Related Issue
Closes #142
📌 Summary
This PR fixes critical security and UX issues in the file upload system by adding:
Client-side file validation
File size restrictions
Upload progress tracking
Upload cancellation support
Inline error/success feedback
Better handling for failed uploads
The previous implementation allowed unrestricted uploads with no validation or progress visibility, creating both security and usability problems.
✅ Changes Made
1. Added File Validation Utility
Created
lib/fileValidation.tsto validate:File size
MIME types
Dangerous file extensions
Blocked unsafe files like:
.exe.sh.bat.cmd.php.dllAlso added a configurable 10MB upload limit.
2. Added
useFileUploadHookCreated reusable upload hook with:
Upload state management
Real-time progress tracking using
XMLHttpRequestUpload cancellation support
Network/server error handling
Reset functionality
States handled:
idlevalidatinguploadingsuccesserrorcancelled3. Updated File Upload Component
Reworked upload UI to include:
Progress bar
Upload percentage
Filename preview
Cancel upload button
Error messages
Success feedback
Accessibility improvements:
aria-labelrole="progressbar"role="alert"4. Added Upload Styles
Created
styles/fileUpload.cssfor:Progress UI
Error/success states
Responsive upload feedback
📂 Files Added / Modified
File | Change -- | -- lib/fileValidation.ts | Added validation utility hooks/useFileUpload.ts | Added upload hook components/chat/FileUpload.tsx | Updated upload component styles/fileUpload.css | Added upload styles🚀 Result
This PR improves:
Security
User experience
Accessibility
Upload reliability
Reusability of upload logic
It also creates a foundation for future enhancements such as:
Multiple file uploads
Drag & drop support
Retry uploads
Chunked uploads
GSSoC Contribution
Submitted under GSSoC 2026.