Skip to content

Do not discard TOTP lockout state write failures #10

Closed

Description

@LunaStev

Problem

TOTPService.Verify increments FailedCount and may set LockedUntil after an invalid code, but discards the result of persisting that state:

_ = service.put("factor", accountID, factor)
return ErrInvalidTOTP

If the database write fails, the caller receives an ordinary invalid-code result while the failure count or lockout was not stored. Repeated requests can therefore continue from stale persisted state instead of enforcing the intended failure limit.

Completion criteria

  • Surface a factor-state persistence failure instead of returning only ErrInvalidTOTP when the failed-attempt update could not be stored.
  • Preserve ErrInvalidTOTP when the update is persisted successfully.
  • Preserve the existing lockout threshold, replay handling, and successful verification state update.
  • Add focused tests that inject a storage write failure before and at the lockout threshold.
  • Verify callers do not misreport a storage failure as ordinary invalid credentials where a server-side failure response is appropriate.

Difficulty: medium.

Activity

  1. added
    bug
    help wanted
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions