Validate uploaded files by content and size before parsing - #1210
Open
holystrings wants to merge 1 commit into
Open
Validate uploaded files by content and size before parsing#1210holystrings wants to merge 1 commit into
holystrings wants to merge 1 commit into
Conversation
Adds byte-size, encoding, and structural checks that run before a file is handed to the import parser. Content type is verified from magic bytes rather than file extension or browser-reported MIME type, so a renamed file can't slip through. Validation failures report which specific check failed, and a rejected file no longer leaves a stale preview visible. Closes Stellopay#1172
Contributor
|
@holystrings is attempting to deploy a commit to the Jagadeesh B's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
File extensions and browser-provided MIME types can be spoofed or simply
wrong, which let unsupported or oversized files reach the import parser
undetected.
Fix
Adds
utils/file-validation.ts, run before any file reaches the parser:before any content is read.
file.nameor
file.type, so a renamed file is caught.TextDecoder(..., { fatal: true })toreject invalid UTF-8 / binary content.
CSV column-consistency) before the real parser runs.
Each check returns a specific error code (
FILE_TOO_LARGE,FILE_EMPTY,UNSUPPORTED_TYPE,INVALID_ENCODING,STRUCTURAL_MISMATCH) so the UI can tell the user exactly what failedinstead of a generic "invalid file" message.
The upload handler now clears preview state in the same branch that
sets the validation error, so a rejected file can no longer leave a
stale preview from a previous successful upload on screen.
Testing
utils/file-validation.test.ts— renamed files, empty files, invalidencoding, and boundary sizes, plus malformed JSON/CSV structure.
invalid file → preview is cleared and error is shown.
npm run lint,npm run type-check,npm test,npm run buildallpass locally.
Acceptance criteria
Closes #1172