Skip to content

Unbounded limit parameter in messageSearch allows heavy database queries and potential DoS #39163

@sahillllllllll-bit

Description

@sahillllllllll-bit

The DDP method messageSearch accepts a user-controlled limit parameter but does not enforce any maximum value.

File: apps/meteor/server/methods/messageSearch.ts

Currently only the type is validated:

check(limit, Match.Optional(Number));

The value is later passed to MongoDB through parseMessageSearchQuery and used in:

Messages.find(query, { ...options }).toArray()

Since no upper bound exists, a client can call:

Meteor.call('messageSearch', 'a', null, 200000, 0)

This forces the server to execute a very large query on the rocketchat_message collection (the largest collection in Rocket.Chat). The result is high CPU usage, slow response times, and event loop blocking. A normal authenticated user can repeatedly trigger this and degrade server availability.

This is effectively a resource-exhaustion / denial-of-service vector.

Expected behavior

Search queries should be paginated and limited to a safe maximum value (similar to other search endpoints).

Proposed solution

Clamp limit and sanitize offset:

limit = Math.min(limit ?? 20, 100);
offset = Math.max(offset ?? 0, 0);

This prevents extremely expensive queries while maintaining current functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions