feat(core): Rate limit forgot password endpoint (#7604)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <netroy@users.noreply.github.com>
This commit is contained in:
Ricardo Espinoza
2023-11-03 13:44:12 -04:00
committed by GitHub
parent acec9bad71
commit 5790e251b8
7 changed files with 52 additions and 12 deletions

View File

@@ -24,12 +24,18 @@ import { isSamlCurrentAuthenticationMethod } from '@/sso/ssoHelpers';
import { UserService } from '@/services/user.service';
import { License } from '@/License';
import { Container } from 'typedi';
import { RESPONSE_ERROR_MESSAGES } from '@/constants';
import { RESPONSE_ERROR_MESSAGES, inTest } from '@/constants';
import { TokenExpiredError } from 'jsonwebtoken';
import type { JwtPayload } from '@/services/jwt.service';
import { JwtService } from '@/services/jwt.service';
import { MfaService } from '@/Mfa/mfa.service';
import { Logger } from '@/Logger';
import { rateLimit } from 'express-rate-limit';
const throttle = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
limit: 5, // Limit each IP to 5 requests per `window` (here, per 5 minutes).
});
@RestController()
export class PasswordResetController {
@@ -46,7 +52,9 @@ export class PasswordResetController {
/**
* Send a password reset email.
*/
@Post('/forgot-password')
@Post('/forgot-password', {
middlewares: !inTest ? [throttle] : [],
})
async forgotPassword(req: PasswordResetRequest.Email) {
if (!this.mailer.isEmailSetUp) {
this.logger.debug(