Skip to content

fix(messages): enforce max content length in sendMessage#272

Merged
omkarhole merged 1 commit into
omkarhole:mainfrom
anshul23102:fix/266-message-content-length
Jun 2, 2026
Merged

fix(messages): enforce max content length in sendMessage#272
omkarhole merged 1 commit into
omkarhole:mainfrom
anshul23102:fix/266-message-content-length

Conversation

@anshul23102
Copy link
Copy Markdown
Contributor

Summary

Closes #266

sendMessage in backend/controllers/directMessage.controller.js validated only that content was non-empty. The global express.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.js only:

  • Added a MAX_CONTENT_LENGTH constant (2000 characters).
  • A type check (typeof content !== 'string') and length check (content.length > MAX_CONTENT_LENGTH) return 400 before any database write.
  • Added fileUrl scheme validation (http/https only) to prevent javascript: URI injection.
  • Added fileName path-separator check to prevent path traversal via the file name field.

Testing

  1. POST /api/v1/messages with content longer than 2000 characters returns 400.
  2. Normal messages within the limit send successfully.
  3. A fileUrl with javascript: scheme returns 400.

Type of Change

  • Bug fix

NSoC '26 contribution

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.
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

@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 omkarhole merged commit 3669af5 into omkarhole:main Jun 2, 2026
0 of 2 checks passed
@omkarhole omkarhole added NSOC'26 Issues for the NSOC 2026 program level1 3 points labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level1 3 points NSOC'26 Issues for the NSOC 2026 program

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: sendMessage in directMessage.controller.js has no maximum length validation on the content field, enabling oversized message payloads

2 participants