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

Improve TOTP field #2795

Merged
merged 11 commits into from
Nov 10, 2023
Merged

Improve TOTP field #2795

merged 11 commits into from
Nov 10, 2023

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Oct 30, 2023

What does this implement/fix?

Fix misaligned TOTP field icon, make password field larger when TOTP is enabled and fix auto-submission to only fire when the user has already put in something into the password field.

Screenshots

TOTP not enabled, before and after

Screenshot from 2023-10-30 08-18-27

TOTP enabled, development-v6

(misaligned icon, small password field)
Screenshot from 2023-10-30 08-19-10

TOTP enabled, this PR

Screenshot from 2023-10-30 08-27-49

Related issue or feature (if applicable): N/A

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories developmental branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

@DL6ER DL6ER requested a review from a team October 30, 2023 07:34
@DL6ER
Copy link
Member Author

DL6ER commented Oct 30, 2023

https://web.dev/articles/sign-in-form-best-practices

This adds a "show password" button:
image

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a bit of space between the https warning and show password
Screenshot at 2023-10-30 20-40-06

@rdwebdesign
Copy link
Member

rdwebdesign commented Nov 3, 2023

Do we need the key icon?
Can we use an eye icon as "show password" button?

Something like this:
password_reveal

@DL6ER
Copy link
Member Author

DL6ER commented Nov 3, 2023

That's a very good solution, if you have this already at hand ;-) Feel free to push ti this branch

@rdwebdesign
Copy link
Member

I will do it in a few minutes.

using input-group and input-group-btn classes.
Also remove the key icon from the password field.

Signed-off-by: RD WebDesign <[email protected]>
@rdwebdesign rdwebdesign requested review from a team and yubiuser November 3, 2023 21:11
Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The click/hover animation (color) changes stays after click until one clicks somewhere else.
Peek 2023-11-03 22-13

I think this should be a hover only.

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entering the password first and submit correct TOTP afterwards shows "Wrong password" briefly before auto-login

Peek 2023-11-03 22-20

login.lp Outdated Show resolved Hide resolved
Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no distinction between entering a wrong password or a wrong TOTP. It will always complain about "Wrong password" and autofocus on the password field - even when the TOTP was wrong.

@rdwebdesign
Copy link
Member

This is the :focus style.
Every button has the same effect, but usually the focus changes to some other element after the click.

We can change the focus to the password field, like this:
button_focus

@DL6ER
Copy link
Member Author

DL6ER commented Nov 4, 2023

Entering the password first and submit correct TOTP afterwards shows "Wrong password" briefly before auto-login

I am not able to reproduce this and looking again at the Javascript code, it also isn't immediately obvious to me how this could be happening. Could you try again and screenshot the Network tab frpm your browser for me with additional screenshots of the reply contents?

Please make sure to have "Persist Logs" enabled for them to "survive" the login process.

image


There is no distinction between entering a wrong password or a wrong TOTP. It will always complain about "Wrong password" and autofocus on the password field - even when the TOTP was wrong.

I will change this to be clearer.

@DL6ER
Copy link
Member Author

DL6ER commented Nov 4, 2023

Wrong password

Screenshot from 2023-11-04 07-16-01

Correct password but wrong 2FA token

Screenshot from 2023-11-04 07-16-17

@yubiuser
Copy link
Member

yubiuser commented Nov 4, 2023

If you think letting users know if they entered a wrong password or a wrong TOTP is a security issue, I'm fine with leaving it as it is. I know this discussion, but it feels a bit like "security by obfuscation". If the second factor is so weak that it can be brute-forced within 30 seconds (before a new TOTP is generated), the second factor is broken anyway.

@DL6ER
Copy link
Member Author

DL6ER commented Nov 5, 2023

Yeah, since online-bruteforcing is prevented by FTL and when they can get physical/root access to either the Pi-hole or the device having the Authenticator app they'll trivially have the TOTP secret, I am fine with showing the user whether it was the password or the token that was wrong. Seem more user-friendly to me.

@yubiuser
Copy link
Member

yubiuser commented Nov 5, 2023

Entering the password first and submit correct TOTP afterwards shows "Wrong password" briefly before auto-login

I'm not seeing this today, but there are two calls to /auth with the second one failing which might be the reason I saw it yesterday. Disabling 2FA, only one /auth request is logged.

Screenshot at 2023-11-05 20-47-49

@yubiuser
Copy link
Member

yubiuser commented Nov 5, 2023

The issue observed was triggered by pasting via Ctl+V being recognized as two events (paste and keyup). I pushed a commit to only trigger on input. I tested it with pre-filled password with: entering TOTP digit by digit, Ctr-V and pasting with mouse. No double login was performed.

@yubiuser
Copy link
Member

yubiuser commented Nov 5, 2023

Is there a reason we prevent a TOTP re-use within 30 seconds?

2023-11-05 23:13:25.448 [399838/T404370] INFO: 2FA code verified successfully at 0
2023-11-05 23:13:33.616 [399838/T404372] WARNING: 2FA code has already been used (-1, 437220), please wait 27 seconds
2023-11-05 23:13:33.618 [399838/T404372] WARNING: API: Invalid 2FA token

This seems to be a too long lock interval.

@DL6ER
Copy link
Member Author

DL6ER commented Nov 6, 2023

Is there a reason we prevent a TOTP re-use within 30 seconds?

It is a Time-Based One-Time Password Algorithm :-)

FTL has the answer to this question here:

Verify code
RFC 6238 (section 4.2): If the calculated value matches the value provided by the user, then the user is authenticated
RFC 6238 (section 4.3): The server MUST NOT accept a TOTP value generated more than 30 seconds in the future
RFC 6238 (section 4.3): The server MUST NOT accept a TOTP value generated more than 30 seconds in the past
RFC 6238 (section 4.3): The server MUST NOT accept a TOTP value it accepted previously

furthermore:

We RECOMMEND a default time-step size of 30 seconds. This default value of 30 seconds is selected as a balance between security and usability.

and sections 5.3:

Note that a prover may send the same OTP inside a given time-step window multiple times to a verifier. The verifier MUST NOT accept the second attempt of the OTP after the successful validation has been issued for the first OTP, which ensures one-time only use of an OTP.

https://github.com/pi-hole/FTL/blob/afb6f865187099557aa6bb3332286ca2bf6730e7/src/api/2fa.c#L223-L224

The point is: Someone can somehow see your keystrokes. You enter your password. You enter your TOTP code. They immediately try to use them to log in and they'd succeed. The motivation behind the last point is that, even though they're still within the 30 second window for that code, it shouldn't work for they - specifically because you already used it.

@DL6ER
Copy link
Member Author

DL6ER commented Nov 6, 2023

With the most recent changes, the login page can much better react on errors:

Initial state

Screenshot from 2023-11-06 11-05-15

No password is supplied, submission is prevented

Screenshot from 2023-11-06 11-06-54

Wrong password is entered

Screenshot from 2023-11-06 11-05-28

Rate-limited

(simply mash Enter)
Screenshot from 2023-11-06 11-06-25

Wrong 2FA token is provided

Screenshot from 2023-11-06 11-07-37

Number of API seats is exceeded

(set webserver.api.max_sessions = 1 and try to login in a private window)
Screenshot from 2023-11-06 11-09-14


For rate-limiting and API seat exhaustion to be reported correctly, you have to use FTL from pi-hole/FTL#1733 (branch new/num_sessions)

@DL6ER
Copy link
Member Author

DL6ER commented Nov 6, 2023

The last commit adds the inclusion of hints from FTL (if available). For example:

Screenshot from 2023-11-06 11-34-05

and

Screenshot from 2023-11-06 11-34-21

@rdwebdesign
Copy link
Member

rdwebdesign commented Nov 8, 2023

I noticed this wasn't reviewed after your last 2 commits.

I tested and it looks fine, but I'm requesting yubiuser approval, because you 2 were discussing about error/warning messages.

@rdwebdesign rdwebdesign requested review from yubiuser and a team November 8, 2023 22:53
@rdwebdesign rdwebdesign merged commit 2497048 into development-v6 Nov 10, 2023
@rdwebdesign rdwebdesign deleted the fix/totp_field branch November 10, 2023 02:38
@sefinek
Copy link

sefinek commented Nov 10, 2023

With the LastPass extension, the width of the input is other.

brave_Ey6VtymkArH8.mp4

@rdwebdesign
Copy link
Member

rdwebdesign commented Nov 11, 2023

This is an external bug.

LastPass extension modifies HTML page content (adding a <div> element to hold the icon) and their modification doesn't work here.
Not our fault, they just make assumptions they shouldn't make.

For example:
if they had used position: absolute instead of relative, the layout wouldn't break here.
lastpass_issue

@sefinek
Copy link

sefinek commented Nov 11, 2023

Maybe it's worth informing them about it?

@yubiuser
Copy link
Member

Sure, go ahead. You can link the issue/analysis here so they know what you are referring to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants