Skip to content

feat: reject file uploads over 25 MiB on the client (Closes #1432) - #1624

Open
waterWang wants to merge 1 commit into
Remitwise-Org:mainfrom
waterWang:feat/file-upload-limit-1432
Open

feat: reject file uploads over 25 MiB on the client (Closes #1432)#1624
waterWang wants to merge 1 commit into
Remitwise-Org:mainfrom
waterWang:feat/file-upload-limit-1432

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

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 via validateFileSize() (max 25 MiB) and MIME type via validateImageMimeType(). 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 pass
  • npm run typecheck — no type errors
  • npm run lint — no lint errors

Closes #1432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden reject file uploads over 25 MiB on the client

1 participant