Skip to content

Commit

Permalink
fix: fixed logger for test, relaxed rate limiting for failed attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 13, 2023
1 parent 3c0f20b commit ccd2f4b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const config = {
smtpMaxQueue: 60,
smtpQueueTimeout: ms('180s'),
smtpLimitMessages: env.NODE_ENV === 'test' ? 10 : 300,
smtpLimitAuth: env.NODE_ENV === 'test' ? Number.MAX_VALUE : 5,
smtpLimitAuthDuration: ms('1d'),
smtpLimitAuth: env.NODE_ENV === 'test' ? Number.MAX_VALUE : 10,
smtpLimitAuthDuration: ms('1h'),
smtpLimitDuration: ms('1d'),
smtpLimitNamespace: `smtp_auth_limit_${env.NODE_ENV.toLowerCase()}`,
supportEmail: env.EMAIL_DEFAULT_FROM_EMAIL,
Expand Down
21 changes: 20 additions & 1 deletion helpers/on-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,30 @@ async function onAuth(auth, session, fn) {
`auth_limit_${config.env}:${session.remoteAddress}`,
0
);
if (count >= config.smtpLimitAuth)
if (count >= config.smtpLimitAuth) {
// alert admins of failed login by IP address
// (until this gets out of hand)
if (session.resolvedClientHostname) {
this.logger.error(
new TypeError(
`${session.resolvedClientHostname} (${parseRootDomain(
session.resolvedClientHostname
)}) has exceeded failed login attempts`
)
);
} else {
this.logger.error(
new TypeError(
`${session.remoteAddress} has exceeded failed login attempts`
)
);
}

throw new SMTPError(
`You have exceeded the maximum number of failed authentication attempts. Please try again later or contact us at ${config.supportEmail}`
// { ignoreHook: true }
);
}
}

// ensure that the token is valid
Expand Down
3 changes: 1 addition & 2 deletions imap-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class IMAP {
namespace: config.smtpLimitNamespace
});

this.logger =
config.env === 'development' ? logger : new Axe({ silent: true });
this.logger = config.env === 'test' ? new Axe({ silent: true }) : logger;

const server = new IMAPServer({
secure,
Expand Down
3 changes: 1 addition & 2 deletions smtp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class SMTP {
namespace: config.smtpLimitNamespace
});

this.logger =
config.env === 'development' ? logger : new Axe({ silent: true });
this.logger = config.env === 'test' ? new Axe({ silent: true }) : logger;

// setup our smtp server which listens for incoming email
// TODO: <https://github.com/nodemailer/smtp-server/issues/177>
Expand Down

0 comments on commit ccd2f4b

Please sign in to comment.