Skip to content

regression: add chat.sendMessage rate limiter - #41966

Merged
dionisio-bot[bot] merged 3 commits into
release-8.8.0from
fix/chat.sendMessage-rate-limiter
Aug 27, 2026
Merged

regression: add chat.sendMessage rate limiter#41966
dionisio-bot[bot] merged 3 commits into
release-8.8.0from
fix/chat.sendMessage-rate-limiter

Conversation

@ricardogarim

@ricardogarim ricardogarim commented Aug 27, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

POST /v1/chat.sendMessage declared no rateLimiterOptions, so it fell back to the REST API default of 10 requests per 60 seconds — a default added in #11251 (2019) for machine-to-machine traffic.

When the web client's send flow moved from the sendMessage Meteor method to REST in #40675, it inherited that budget. The method had its own rule (5 messages per second, since 2015), so the allowance dropped from 300 to 10 messages per minute and the 11th message returned 429.

This declares the previous allowance on the endpoint, the same way users.setStatus does:

rateLimiterOptions: { numRequestsAllowed: 5, intervalTimeInMS: 1000 },

Issue(s)

Steps to test or reproduce

Requires a server started without TEST_MODE and with API_Enable_Rate_Limiter_Dev enabled — otherwise no rule is registered and no X-RateLimit-* headers are returned.

As a regular user without api-bypass-rate-limit:

  1. Send 12 messages ~300 ms apart → all 200. The 11th used to return 429.
  2. Send 10 messages as fast as possible → first 5 200, rest 429.
  3. Wait ~1 s and send again → 200. The window is 1 second, not 60.
  4. Repeat step 2 with the bot role → no rejections.

Further comments

The REST limiter buckets by IP address, not by user — the counter key is IPAddr + route, with no per-route way to change it. This allowance is therefore shared by everyone behind one address, unlike the Meteor rule, which was keyed by userId. Keying on userId would remove that ceiling, but it affects every route and is deliberately left out of this fix.

There's a follow up task to handle per user: CORE-2637

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added rate limiting to chat message requests, allowing up to 5 requests per second.
    • Authorized integrations can bypass limits when granted the appropriate permissions.
    • API rate-limit bypasses now support route-specific permissions for more flexible access control.
  • Bug Fixes

    • Improved rate-limit exemption handling to apply permissions consistently across API routes.
    • Ensured users without the required permissions remain subject to configured request limits.

@dionisio-bot

dionisio-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d3c64d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ricardogarim ricardogarim added this to the 8.9.0 milestone Aug 27, 2026
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ad80fa8-f58a-4eb8-a486-0fcb55c09531

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6753d and d3c64d8.

📒 Files selected for processing (3)
  • apps/meteor/server/api/ApiClass.ts
  • apps/meteor/server/api/api.ts
  • apps/meteor/server/api/definition.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
⚠️ CI failures not shown inline (4)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**
🧰 Additional context used
📓 Path-based instructions (2)
The main Rocket.Chat Meteor application resides in `apps/meteor/`; place its application code there rather than in other monorepo areas.

📄 CodeRabbit inference engine (CLAUDE.md)

Files:

  • apps/meteor/server/api/api.ts
  • apps/meteor/server/api/definition.ts
  • apps/meteor/server/api/ApiClass.ts
Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

Files:

  • apps/meteor/server/api/api.ts
  • apps/meteor/server/api/definition.ts
  • apps/meteor/server/api/ApiClass.ts
🧠 Learnings (2)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/api/api.ts
  • apps/meteor/server/api/definition.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/api/api.ts
  • apps/meteor/server/api/definition.ts
🔇 Additional comments (3)
apps/meteor/server/api/definition.ts (1)

102-107: LGTM!

Also applies to: 121-121, 136-136

apps/meteor/server/api/api.ts (1)

8-8: LGTM!

Also applies to: 25-25

apps/meteor/server/api/ApiClass.ts (1)

21-21: LGTM!

Also applies to: 30-30, 49-49, 130-130, 418-418


Walkthrough

The API rate limiter now supports route-specific bypass permissions. The chat.sendMessage endpoint limits requests to five per second and exempts users with send-many-messages. Unit tests cover global and route-specific bypass permissions.

Changes

Chat message rate limiting

Layer / File(s) Summary
Rate-limit bypass contract and helper
apps/meteor/server/api/definition.ts, apps/meteor/server/api/api.ts, apps/meteor/server/api/api.helpers.ts, apps/meteor/tests/unit/server/api/canBypassRateLimit.spec.ts
RateLimiterOptions now includes bypassPermissions. canBypassRateLimit checks global and route-specific permissions. Unit tests cover matching and non-matching permissions.
Rate-limit verification and chat configuration
apps/meteor/server/api/ApiClass.ts, apps/meteor/server/api/v1/chat.ts
Rate-limit verification uses route-configured bypass permissions. chat.sendMessage allows five requests per second and exempts send-many-messages.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🔵 Low · up to d3c64

The endpoint now allows five messages per second, while users with the send-many-messages permission can bypass the limit. Because limiting is shared by IP address, one user can still throttle others on the same network, and permission grants should be confirmed by the owning team before merge.

Suggested labels: type: bug

Suggested reviewers: sampaiodiego

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a rate limiter to the chat.sendMessage endpoint to address a regression.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Warning

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-8.8.0@1c01809). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##             release-8.8.0   #41966   +/-   ##
================================================
  Coverage                 ?   69.38%           
================================================
  Files                    ?     4254           
  Lines                    ?   168903           
  Branches                 ?    30153           
================================================
  Hits                     ?   117190           
  Misses                   ?    46555           
  Partials                 ?     5158           
Flag Coverage Δ
e2e 58.79% <ø> (?)
e2e-api 45.88% <0.00%> (?)
unit 71.31% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ricardogarim
ricardogarim changed the base branch from develop to release-8.8.0 August 27, 2026 13:15
@ricardogarim ricardogarim modified the milestones: 8.9.0, 8.8.0 Aug 27, 2026
@ricardogarim
ricardogarim force-pushed the fix/chat.sendMessage-rate-limiter branch from 6e14f80 to 7cb492c Compare August 27, 2026 13:21
@ricardogarim ricardogarim changed the title fix: add chat.sendMessage rate limiter regression: add chat.sendMessage rate limiter Aug 27, 2026
@ricardogarim
ricardogarim marked this pull request as ready for review August 27, 2026 13:23
@ricardogarim
ricardogarim requested a review from a team as a code owner August 27, 2026 13:23

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/server/api/v1/chat.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/server/api/ApiClass.ts Outdated
KevLehman
KevLehman previously approved these changes Aug 27, 2026
@rc-layne

rc-layne Bot commented Aug 27, 2026

Copy link
Copy Markdown

⚠️ Layne — scan incomplete

Layne could not analyze all changed content. Review the Check Run summary before merging.

@FragaKrummenauer FragaKrummenauer added the stat: QA assured Means it has been tested and approved by a company insider label Aug 27, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 27, 2026
@dionisio-bot
dionisio-bot Bot merged commit 01d81c2 into release-8.8.0 Aug 27, 2026
56 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/chat.sendMessage-rate-limiter branch August 27, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants