flatnotes icon indicating copy to clipboard operation
flatnotes copied to clipboard

Allow TOTP to be reused (within its lifetime)

Open kontaxis opened this issue 2 months ago • 2 comments

When FLATNOTES_AUTH_TYPE is totp the user cannot log in, log out, and log back in within 30 seconds. This change address the issue.

How to reproduce the issue:

  1. Confirm that FLATNOTES_AUTH_TYPE is totp, FLATNOTES_USERNAME and FLATNOTES_PASSWORD are defined.
  2. Log into Flatnotes and note the current 2FA code. (In your 2FA application)
  3. Immediately log out and try to log back in.
  4. Observe that the 2FA code hasn't changed. If it has, go to step (2).
  5. Observe that login fails with an error message indicating incorrect credentials.

Expected results: At step 5 login is successful given the correct username, password, and the current 2FA code.

Actual results: Log in fails.

Discussion: Flatnotes keeps track of the current 2FA code and does not allow it to be reused. However the user can't get a new code on demand and pyotp rotates codes every 30 seconds. So if the user logs in, logs out, and tries to log in again before a new 2FA code is available they'll get a confusing "incorrect login credentials" message and no recourse. Given the pyotp behavior I'm not sure what's the purpose of the current Flatnotes logic.

This change allows 2FA codes to be reused as long as they match totp.now()

kontaxis avatar Nov 06 '25 18:11 kontaxis