auth: add local TOTP enrollment helpers#103
Conversation
Greptile SummaryThis PR implements five local TOTP lifecycle helpers ( Confidence Score: 5/5Safe to merge; the single finding is a P2 edge case on the storage-error path that doesn't affect the primary auth or enumeration-resistance paths. Only P2 findings present. The implementation correctly handles all major security concerns: key isolation, enumeration resistance across all normal failure modes, active-TOTP preservation during re-enrollment, and disabled/locked account rejection. The one gap (storage errors returning raw error strings) is a minor inconsistency on an exceptional path. src/stdlib/auth/local.rs — storage error path in Important Files Changed
Reviews (3): Last reviewed commit: "fix: harden local TOTP verification erro..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
Adds first-class local-auth TOTP enrollment/verification helpers to std/auth, persisting lifecycle state in reserved local-identity metadata (auth.totp) and documenting staged password → TOTP flows.
Changes:
- Added new
std/authnative functions for TOTP enrollment, confirmation, verification, status, and reset. - Implemented local-record helpers that store/read TOTP lifecycle state in local identity metadata without leaking secrets in safe payloads.
- Updated typechecker signatures, added tests, and extended user-facing docs/design docs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/typechecker.rs |
Adds type signatures + typechecker tests for new std/auth TOTP helpers. |
src/stdlib/auth/primitives.rs |
Extends verify_totp_code to accept an issuer (used by local TOTP helpers). |
src/stdlib/auth/local.rs |
Implements local TOTP lifecycle record helpers + metadata utilities (auth.totp). |
src/stdlib/auth.rs |
Exposes new std/auth native functions, shared arg/options parsing helpers, and adds integration tests around non-leakage + reenrollment behavior. |
docs/STDLIB_REFERENCE.md |
Documents new std/auth functions and examples. |
docs/AI_AGENT_GUIDE.md |
Adds guidance and sample flow for local TOTP enrollment + staged login challenges. |
design-docs/dd-043-auth-excellence.md |
Marks DD-043 PR2 items complete and records deferred lockout/throttling. |
Summary
Implements DD-043 PR 2: Strong TOTP Support for local auth.
begin_totp_enrollment(identifier, options?)confirm_totp_enrollment(identifier, code, options?)verify_local_totp(identifier, code, options?)totp_status(identifier, options?)reset_totp(identifier, options?)auth.totp) instead of requiring template-owned TOTP tables.local_user,totp_status,current_user); enrollment returns only one-time setup URI material for QR display.enabled=truewhilepending=true, avoiding a password-only downgrade window.Test Plan
cargo test totp -- --nocapturecargo test auth -- --test-threads=1cargo testcargo fmtcargo fmt -- --checkcargo build --profile dev-release./target/dev-release/ntnt docs --generategit diff --check./target/dev-release/ntnt validate examples/./target/dev-release/ntnt lint examples/Notes:
Review
Known Limitations / Deferrals
verify_local_totp(...)verifies codes but does not own failed-attempt throttling, lockout policy, or last-used-step replay tracking. DD-043 now records that as a future std/auth refinement if real apps need it centralized; apps should wrap TOTP routes with their normal rate limiting/backoff today.