Skip to content
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

#2812 user cannot sign in too many failed attempts change #2893

Merged
merged 6 commits into from
Sep 29, 2022
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
6 changes: 5 additions & 1 deletion verification/curator-service/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class AuthController {
req.logIn(user, (err) => {
if (err) return next(err);
});

loginLimiter.resetKey(req.ip);
res.status(200).json(user);
},
)(req, res, next);
Expand Down Expand Up @@ -475,6 +475,8 @@ export class AuthController {
.json({ message: 'Old password is incorrect' });
}

resetPasswordLimiter.resetKey(req.ip);

updateFailedAttempts(
currentUser._id,
AttemptName.ResetPassword,
Expand Down Expand Up @@ -682,6 +684,8 @@ export class AuthController {
// Send confirmation email to the user
const user = result.value as IUser;

resetPasswordWithTokenLimiter.resetKey(req.ip);

updateFailedAttempts(
userId,
AttemptName.ResetPasswordWithToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import rateLimit from 'express-rate-limit';

export const loginLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 60 minutes
max: 4, // Limit each IP to 4 requests per `window` (here, per 20 minutes)
max: 6, // Limit each IP to 6 requests per `window` (here, per 60 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
handler: function (req, res /*next*/) {
Expand All @@ -15,7 +15,7 @@ export const loginLimiter = rateLimit({

export const registerLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 60 minutes
max: 4,
max: 6,
standardHeaders: true,
legacyHeaders: false,
handler: function (req, res) {
Expand All @@ -24,12 +24,11 @@ export const registerLimiter = rateLimit({
'You sent too many requests. Please wait a while then try again',
});
},
skipSuccessfulRequests: true,
});

export const resetPasswordLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 60 minutes
max: 4,
max: 6,
standardHeaders: true,
legacyHeaders: false,
handler: function (req, res) {
Expand All @@ -43,7 +42,7 @@ export const resetPasswordLimiter = rateLimit({

export const forgotPasswordLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 60 minutes
max: 4,
max: 6,
standardHeaders: true,
legacyHeaders: false,
handler: function (req, res) {
Expand All @@ -52,12 +51,11 @@ export const forgotPasswordLimiter = rateLimit({
'You sent too many requests. Please wait a while then try again',
});
},
skipSuccessfulRequests: true,
});

export const resetPasswordWithTokenLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 60 minutes
max: 4,
max: 6,
standardHeaders: true,
legacyHeaders: false,
handler: function (req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('LandingPage', function () {
cy.get('#password').type('tT$5aaaaak');
cy.get('#passwordConfirmation').type('tT$5aaaaak');
cy.get('#isAgreementChecked').check();
for (let i = 0; i < 5; i++) {
for (let i = 0; i < 7; i++) {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1500);
cy.get('button[data-testid="sign-up-button"]').click();
Expand All @@ -230,7 +230,7 @@ describe('LandingPage', function () {
cy.contains('Sign in!').click();
cy.get('#email').type('test@example.com');
cy.get('#password').type('test');
for (let i = 0; i < 5; i++) {
for (let i = 0; i < 7; i++) {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1500);
cy.get('button[data-testid="sign-in-button"]').click();
Expand Down