-
Notifications
You must be signed in to change notification settings - Fork 13k
fix: handle shouldAddRateLimitToRoute exception to prevent the server from crashing
#35117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #35117 +/- ##
========================================
Coverage 59.22% 59.22%
========================================
Files 2824 2824
Lines 67980 67980
Branches 15117 15117
========================================
Hits 40259 40259
Misses 24892 24892
Partials 2829 2829
Flags with carried forward coverage won't be shown. Click here to find out more. |
|
shouldAddRateLimitToRoute to fix rate limiter logic and prevent crashesshouldAddRateLimitToRoute to fix rate limiter logic
2353766 to
3e78079
Compare
3e78079 to
988b43f
Compare
shouldAddRateLimitToRoute to fix rate limiter logicshouldAddRateLimitToRoute exception to prevent the server from crashing
|
Hi, I am curious about why the fallback value is set to Rocket.Chat/apps/meteor/server/settings/rate.ts Lines 67 to 70 in 1198e51
|
It was solely a typo. Good catch, @imunique-ZJ. Thanks for noticing it and we've opened a PR to fix the typo: #35180. It's pending approval and we will merge it before the next release. Much appreciated |
Proposed changes (including videos or screenshots)
When running the
developbranch withyarn dsvinstead ofTEST_MODE=TRUE yarn dsvwe get the following error:This error originates from
Rocket.Chat/apps/meteor/app/api/server/api.ts, more specifically in the function responsible for refreshing API routes and applying rate-limiting:This function:
shouldAddRateLimitToRoute(route.options).addRateLimiterRuleForRoutesif the check returnstrue.The function
addRateLimiterRuleForRoutesenforces that bothnumRequestsAllowedandintervalTimeInMSmust be defined - otherwise, it will throw an error:However,
shouldAddRateLimitToRoutedoes not strictly enforce thatnumRequestsAllowedandintervalTimeInMSare defined - instead, it only checks whetherrateLimiterOptionsis an object:As a result, the following configuration evaluates to
true- even ifsettings.get('API_Enable_Rate_Limiter_Limit_Time_Default')isundefined(which can happen when the server starts for the first time), leading to the uncaught exception:This PR handles the exception to prevent the server from crashing and adds a fallback value to
intervalTimeInMS: settings.get('API_Enable_Rate_Limiter_Limit_Time_Default')in theusers.registerroute.Issue(s)
SB-763
Steps to test or reproduce
Fetch latest
developbranch and start the server withyarn dsv.Further comments