Skip to content

fix(auth): expose matched totp step so callers can reject replayed codes - #368

Merged
BryanFRD merged 1 commit into
mainfrom
fix/348-totp-replay
Oct 25, 2026
Merged

BryanFRD merged 1 commit into
mainfrom
fix/348-totp-replay

Conversation

@BryanFRD

Copy link
Copy Markdown
Contributor

Adds TotpEnrollment::verify_step_at and verify_step_now, which return the matched step and reject any step at or before last_used_step. Callers persist the returned step atomically with the login to enforce RFC 6238 section 5.2.

verify_at and verify_now keep their signatures (additive, not breaking).

Closes #348

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct. In totp-rs 6.0.0, check returns Option<u64>, the first matching counter in the skew window, so filtering on step > last gives the RFC 6238 §5.2 one-time-use rule. is_none_or needs Rust 1.82, and the MSRV is 1.85. Keeping the local unix_now() instead of check_current is right, because check_current panics on a pre-epoch clock.

Nit: verify_at and verify_now still accept replayed codes, and their docs don't say so. Add a line pointing callers to verify_step_* for login, or deprecate them, so new code doesn't pick the version without replay protection.

@BryanFRD
BryanFRD merged commit e87df11 into main Oct 25, 2026
19 checks passed
@BryanFRD
BryanFRD deleted the fix/348-totp-replay branch October 25, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(auth): return the matched totp step so callers can reject replayed codes

1 participant