Repository navigation
Accept TOTP codes from one time step either side of the current one. #9783 - #10899
Conversation
|
No actionable comments were generated in the recent review. WalkthroughTOTP login and registration accept codes from the current 30-second step or either adjacent step. Tests verify that codes two steps away are rejected. ChangesTOTP validation window
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
…gadmin-org#9783 Both registration and login previously accepted only the code for the current 30-second step, so a small difference between the server and authenticator clocks caused "Failed to validate the code". Pass valid_window=1 to pyotp's verify() in both places.
pyotp 2.12 requires secrets of at least 112 bits, makes counter_offset keyword-only and reads the clock from time.time(), so use a 160-bit secret, generate codes from timestamps and freeze both clock sources.
aa27447 to
15e6b4f
Compare
Summary
web/pgadmin/authenticate/mfa/authenticator.pynow passvalid_window=1to pyotp'sverify(), accepting one step either side of the current one, which is common practice for TOTP. Nothing else in the MFA flow changes.The reporter says both clocks are synchronised, so this may not resolve their case on its own (a lost session during registration would also produce this error, and I've asked about that on the issue); hence this PR is related to the issue rather than closing it.
Test plan
test_totp_window.pyscenarios, with the clock frozen: codes for the previous, current and next step are accepted at login and registration, and codes two steps away are rejected. Both fail without the fix.runtests.py --pkg authenticate.mfa(22 tests) passes.pycodestyleon the changed files.Related to #9783
Summary by CodeRabbit