feat(identity): resend cooldown + verification throttling (closes #199)#202
Open
antosubash wants to merge 1 commit into
Open
feat(identity): resend cooldown + verification throttling (closes #199)#202antosubash wants to merge 1 commit into
antosubash wants to merge 1 commit into
Conversation
…199) Adds IVerificationThrottle backed by IFusionCache and wires it into the four endpoints called out in #199: - POST /Identity/Account/ResendEmailConfirmation - POST /Identity/Account/Manage/Email (re-sends change-email link) - POST /Identity/Account/Manage/SendPhoneVerificationCode - POST /Identity/Account/Manage/ConfirmPhoneNumber Resend cooldown is per-user, per-channel (default 60s). When the caller is inside the cooldown, the response shape is identical to the success path (no information leak) but a Retry-After header is set so well-behaved clients back off. Attempt cap on ConfirmPhoneNumber locks the (user, phone-channel) pair after MaxFailedAttempts (default 5) for LockoutDuration (default 15 minutes). While locked out, ChangePhoneNumberAsync is not called at all — the 6-digit search space cannot be drained against the lockout. A successful confirmation clears the counter. Configurable via Identity:VerificationThrottle in appsettings. Tests: 8 new unit tests cover first-allow, cooldown-rejects-with- retry-after, post-cooldown-allow, per-channel isolation, per-user isolation, lockout-after-max-failures, success-clears- lockout, and not-locked-out-by-default. Full Users suite still 70/70.
Deploying simplemodule-website with
|
| Latest commit: |
7f82c93
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a4d6764a.simplemodule-website.pages.dev |
| Branch Preview URL: | https://issue-199-identity-throttlin.simplemodule-website.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #199.
Adds
IVerificationThrottle(FusionCache-backed) and wires it into the four endpoints called out in the issue:POST /Identity/Account/ResendEmailConfirmationPOST /Identity/Account/Manage/Email(re-sends the change-email link)POST /Identity/Account/Manage/SendPhoneVerificationCodePOST /Identity/Account/Manage/ConfirmPhoneNumberResend cooldown
Per-user, per-channel — default 60s, configurable via
Identity:VerificationThrottle:ResendCooldown. When a caller is inside the cooldown:Retry-Afterheader is set so well-behaved clients back off.Attempt cap on ConfirmPhoneNumber
After
MaxFailedAttempts(default 5) the (user, phone-channel) pair is locked out forLockoutDuration(default 15 minutes). While locked,UserManager.ChangePhoneNumberAsyncis not called — the 6-digit search space cannot be drained against the lockout. A successful confirmation clears the counter and the lockout.Auditing
Every resend POST and every confirmation POST already runs through
AuditMiddleware, so the audit log captures method/path/user/IP/status/timing without changes. The throttle decisions show up viaRetry-Afterand distinct status messages.Test plan
dotnet test modules/Users/tests --filter VerificationThrottle— 8/8 (first allow, cooldown rejects with retry-after, post-cooldown allow, per-channel, per-user, lockout-after-max-failures, success-clears-lockout, not-locked-by-default)dotnet test modules/Users/tests— 70/70 (no regressions)dotnet build— greencurl -X POST /Identity/Account/ResendEmailConfirmationtwice within 60s; second response carriesRetry-After. Five wrong codes against ConfirmPhoneNumber → sixth attempt short-circuits with "Too many failed attempts."Configuration
{ "Identity": { "VerificationThrottle": { "ResendCooldown": "00:01:00", "MaxFailedAttempts": 5, "LockoutDuration": "00:15:00" } } }