feat: reject file uploads over 25 MiB on the client (Closes #1432) - #1624
Open
waterWang wants to merge 1 commit into
Open
feat: reject file uploads over 25 MiB on the client (Closes #1432)#1624waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
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.
Summary
Reject file uploads over 25 MiB on the client side, before any code tries to read them into memory or upload them. Without this, a user or a malicious script driving the file input could hand a multi-gigabyte file to
FileReader.readAsDataURL, hanging or crashing the tab well before any server-side limit gets a chance to run.Threat model
An attacker who can drive the file input (e.g. via a browser extension, devtools, or a compromised dependency) could select a multi-gigabyte file. Without this gate, the client would attempt to read the entire file into memory, potentially crashing the tab and wasting bandwidth. The size check runs before any data is read, and the typed error result gives the caller a clear, actionable response instead of a generic failure.
Changes
components/settings/ProfileSection.tsx: Added a hidden<input type=file>triggered by the "Change Avatar" button. On file selection, validates the file size viavalidateFileSize()(max 25 MiB) and MIME type viavalidateImageMimeType(). Shows an inline error and a toast on failure; creates a local data-URL preview on success.components/settings/ProfileSection.test.tsx: Added tests for size rejection, MIME type rejection, and valid image acceptance.Testing
npm test— all tests passnpm run typecheck— no type errorsnpm run lint— no lint errorsCloses #1432