fix(messages): enforce max content length in sendMessage#272
Merged
omkarhole merged 1 commit intoJun 2, 2026
Merged
Conversation
Closes omkarhole#266 sendMessage validated only that content was non-empty. The global express.json limit (100 KB) is too permissive for a single chat message, allowing a caller to store and transmit up to 100 KB of text in every message document. Add a MAX_CONTENT_LENGTH constant (2000 characters) checked before any database write. Non-string content also returns 400. Also add scheme validation on fileUrl (http/https only) and path-separator check on fileName to prevent URI and path injection via these fields.
|
@anshul23102 is attempting to deploy a commit to the omkarhole's projects Team on Vercel. A member of the Team first needs to authorize it. |
omkarhole
approved these changes
Jun 2, 2026
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
Closes #266
sendMessageinbackend/controllers/directMessage.controller.jsvalidated only thatcontentwas non-empty. The globalexpress.json({ limit: '100kb' })body limit is too permissive for a single chat message. A caller could store and transmit up to 100 KB in every message document, causing oversized inbox payloads and MongoDB document bloat.What Changed
backend/controllers/directMessage.controller.jsonly:MAX_CONTENT_LENGTHconstant (2000 characters).typeof content !== 'string') and length check (content.length > MAX_CONTENT_LENGTH) return400before any database write.fileUrlscheme validation (http/https only) to prevent javascript: URI injection.fileNamepath-separator check to prevent path traversal via the file name field.Testing
/api/v1/messageswithcontentlonger than 2000 characters returns400.fileUrlwithjavascript:scheme returns400.Type of Change
NSoC '26 contribution