Skip to content

Commit

Permalink
Allow users with 2fa to bypass loginattempts filter
Browse files Browse the repository at this point in the history
If they have 2FA, this becomes unnecessary anyway.
  • Loading branch information
mia-pi-git committed Jul 23, 2024
1 parent 650b379 commit fac270d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,16 @@ export class Session {
const userid = toID(name);
let attempts = (await loginattempts.get(userid)) as {time: number, count: number};
if (attempts) {
// too many attempts, no valid login session from that ip on that userid
if (attempts.count >= 500 && !(await sessions.selectOne()`WHERE ip = ${ip} AND userid = ${userid}`)) {
const shouldBeBlocked = (
// too many attempts
attempts.count >= 500 && !(
// has an active login session on that IP - it's them, let them through
await sessions.selectOne()`WHERE ip = ${ip} AND userid = ${userid}` ||
// 2fa, allow them through
!!(await users.get(userid))?.email
)
);
if (shouldBeBlocked) {
attempts.count++;
await loginattempts.update(userid, {time: time(), count: attempts.count});
throw new ActionError(
Expand Down

0 comments on commit fac270d

Please sign in to comment.