Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions apps/meteor/app/api/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Users } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import type { JoinPathPattern, Method } from '@rocket.chat/rest-typings';
import { wrapExceptions } from '@rocket.chat/tools';
import express from 'express';
import type { Request, Response } from 'express';
import { Accounts } from 'meteor/accounts-base';
Expand Down Expand Up @@ -404,10 +405,14 @@
public reloadRoutesToRefreshRateLimiter(): void {
this._routes.forEach((route) => {
if (this.shouldAddRateLimitToRoute(route.options)) {
this.addRateLimiterRuleForRoutes({
routes: [route.path],
rateLimiterOptions: route.options.rateLimiterOptions || defaultRateLimiterOptions,
endpoints: Object.keys(route.endpoints).filter((endpoint) => endpoint !== 'options'),
wrapExceptions(() =>
this.addRateLimiterRuleForRoutes({
routes: [route.path],
rateLimiterOptions: route.options.rateLimiterOptions || defaultRateLimiterOptions,
endpoints: Object.keys(route.endpoints).filter((endpoint) => endpoint !== 'options'),
}),
).catch((error) => {
console.error(error.message);
});
}
});
Expand All @@ -426,10 +431,10 @@
throw new Meteor.Error('"rateLimiterOptions" must be an object');
}
if (!rateLimiterOptions.numRequestsAllowed) {
throw new Meteor.Error('You must set "numRequestsAllowed" property in rateLimiter for REST API endpoint');
throw new Meteor.Error(`You must set "numRequestsAllowed" property in rateLimiter for REST API endpoint: ${routes}`);
}
if (!rateLimiterOptions.intervalTimeInMS) {
throw new Meteor.Error('You must set "intervalTimeInMS" property in rateLimiter for REST API endpoint');
throw new Meteor.Error(`You must set "intervalTimeInMS" property in rateLimiter for REST API endpoint: ${routes}`);
}
const addRateLimitRuleToEveryRoute = (routes: string[]) => {
routes.forEach((route) => {
Expand Down Expand Up @@ -562,13 +567,13 @@
const api = this;
(operations[method as keyof Operations<TPathPattern, TOptions>] as Record<string, any>).action =
async function _internalRouteActionHandler() {
this.requestIp = getRequestIP(this.request)!;

Check warning on line 570 in apps/meteor/app/api/server/api.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Forbidden non-null assertion

if (options.authRequired || options.authOrAnonRequired) {
const user = await api.authenticatedRoute(this.request);
this.user = user!;

Check warning on line 574 in apps/meteor/app/api/server/api.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Forbidden non-null assertion
this.userId = String(this.request.headers['x-user-id']);
this.token = (this.request.headers['x-auth-token'] &&

Check warning on line 576 in apps/meteor/app/api/server/api.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Forbidden non-null assertion
Accounts._hashLoginToken(String(this.request.headers['x-auth-token'])))!;
}

Expand Down Expand Up @@ -645,7 +650,7 @@
connection,
};

Accounts._setAccountData(connection.id, 'loginToken', this.token!);

Check warning on line 653 in apps/meteor/app/api/server/api.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Forbidden non-null assertion

this.userId &&
(await api.processTwoFactor({
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ API.v1.addRoute(
authRequired: false,
rateLimiterOptions: {
numRequestsAllowed: settings.get('Rate_Limiter_Limit_RegisterUser') ?? 1,
intervalTimeInMS: settings.get('API_Enable_Rate_Limiter_Limit_Time_Default'),
intervalTimeInMS: settings.get('API_Enable_Rate_Limiter_Limit_Time_Default') ?? 600000,
},
validateParams: isUserRegisterParamsPOST,
},
Expand Down
Loading