RocketChat / RocketChat/Rocket.Chat

Improve security checks for URL-based avatar downloads

Open
#39,594 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: feature
Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

Description

While reviewing the recent fix addressing unbounded memory consumption in avatar URL uploads, I noticed a few additional edge cases that could further strengthen the security of the implementation.

The current fix correctly enforces FileUpload_MaxFileSize and prevents large responses from being buffered entirely in memory. However, there are a few scenarios that may still benefit from additional safeguards.

Potential Improvements

  1. Missing or incorrect Content-Length header

Some servers may not include a Content-Length header or may return an incorrect value. In such cases, relying solely on the header check could be insufficient. The streaming byte limit should always be enforced regardless of whether the header is present or accurate.

  1. Request timeout handling

A remote server could intentionally send data very slowly, potentially keeping the connection open for an extended period of time. Adding a timeout mechanism for the fetch request could help prevent resource exhaustion from slow responses.

  1. MIME type validation

Since this endpoint processes avatar images, validating the response Content-Type could prevent non-image files from being stored as avatars. Accepting only expected formats (such as image/png, image/jpeg, or image/webp) would improve security and consistency.

Expected Behavior

The avatar download mechanism should:

Enforce maximum file size limits even when Content-Length is missing or incorrect

Apply request timeouts to prevent slow or stalled downloads

Validate the MIME type to ensure only supported image formats are accepted

Additional Context

This issue is related to the recent security fix addressing unbounded memory consumption during avatar URL downloads.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the avatar URL download implementation and reviewing the recent fix for unbounded memory consumption. Check how responses are handled when Content-Length is missing or incorrect, how request timeouts are configured, and where MIME types are validated. Done means enforcing the byte limit, timeout, and supported-image MIME checks described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.