Repository navigation
Fix Core Identity email lookup - #10222
Merged
Merged
Conversation
Lookups a valid user email instead of using unvalidated user input. ---- #### AI description (iteration 1) #### PR Classification Bug fix to ensure email notifications are sent to the stored email address rather than the user-provided input email address. #### PR Summary Fixes a security/correctness issue where email confirmations and password reset emails could be sent to an email address different from the one stored in the user's account (e.g., when different casing is used). The changes ensure that the stored email address from `GetEmailAsync` is always used when sending emails, and throws an exception if the stored email is null. - `IdentityApiEndpointRouteBuilderExtensions.cs`: Modified `/resendConfirmationEmail` and `/forgotPassword` endpoints to retrieve and use the stored email via `GetEmailAsync` instead of using the request email directly - `ForgotPassword.cshtml.cs` (V4 and V5): Updated to fetch stored email from `UserManager` and validate it's not null before sending password reset emails - `ResendEmailConfirmation.cshtml.cs` (V4 and V5): Updated to fetch stored email from `UserManager` and validate it's not null before sending confirmation emails - `MapIdentityApiTests.cs`: Added comprehensive tests to verify emails are sent to stored addresses and that null email scenarios throw `InternalServerError` <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Missing stored emails introduce inconsistent error responses and unhandled UI failures, while the UI behavior lacks regression coverage.
8 open findings
Preserve generic 200 response when stored email is missing · New Avoid 500 errors for accounts with missing emails · New Handle missing emails with the generic recovery response · New Avoid 500 errors for accounts with missing emails · New Handle missing emails with the generic recovery response · New Test case-insensitive forgot-password email handling · New Test case-insensitive resend email handling · New Remove the unintended UTF-8 BOM · New
What changed in this PR
Updates Identity email workflows to send messages to the user’s stored email rather than request input.
Changes:
- Uses stored emails across Core API and Default UI flows.
- Adds API functional tests for casing and missing-email scenarios.
- Handles unavailable stored emails explicitly.
| File | Description |
|---|---|
V5/Account/ResendEmailConfirmation.cshtml.cs |
Uses the stored resend address. |
V5/Account/ForgotPassword.cshtml.cs |
Uses the stored reset address. |
V4/Account/ResendEmailConfirmation.cshtml.cs |
Applies the V4 resend fix. |
V4/Account/ForgotPassword.cshtml.cs |
Applies the V4 reset fix. |
MapIdentityApiTests.cs |
Adds endpoint behavior tests. |
IdentityApiEndpointRouteBuilderExtensions.cs |
Updates Core Identity email endpoints. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
DeagleGross
approved these changes
Oct 14, 2026
This was referenced Oct 19, 2026
This was referenced Oct 21, 2026
This was referenced Oct 29, 2026
haileymck
pushed a commit
to dotnet/Scaffolding
that referenced
this pull request
Nov 13, 2026
A similar PR to dotnet/dotnet#10222 fixing scaffolding templates ---- #### AI description (iteration 1) #### PR Classification Bug fix: Identity scaffolding templates now use the user's stored email address instead of the user-submitted input to prevent email address spoofing in account confirmation and password reset emails. #### PR Summary Updates Identity scaffolding templates (Razor Pages and Blazor) across `VS.Web.CG.Mvc` and `dotnet-scaffold` to retrieve and use the stored email from `UserManager`/`_userManager` instead of `Input.Email` when sending confirmation or password reset emails, throwing an `InvalidOperationException` if no stored email exists. - `ForgotPassword.cs`/`.tt` (Blazor Identity, both `VS.Web.CG.Mvc` and `dotnet-scaffold`): replaces `Input.Email` with `storedEmail` fetched via `UserManager.GetEmailAsync(user)` for password reset emails. - `ResendEmailConfirmation.cs`/`.tt` (Blazor Identity, both locations): replaces `Input.Email` with `storedEmail` for confirmation emails. - `Account.ForgotPassword.cs.cshtml` (Bootstrap4/Bootstrap5) and `ForgotPasswordModel.cs`/`.tt`: uses `_userManager.GetEmailAsync(user)` instead of `Input.Email` when sending reset password email. - `Account.ResendEmailConfirmation.cs.cshtml` (Bootstrap4/Bootstrap5) and `ResendEmailConfirmationModel.cs`/`.tt`: same stored-email validation and usage for confirmation emails. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Co-authored-by: Dmitrii Korolev <[email protected]>
haileymck
pushed a commit
to dotnet/Scaffolding
that referenced
this pull request
Nov 13, 2026
A similar PR to dotnet/dotnet#10222 fixing scaffolding templates ---- #### AI description (iteration 1) #### PR Classification Bug fix: ensures email notifications use the user's stored email address instead of potentially stale/mismatched `Input.Email` form value, with validation to guard against null/empty stored emails. #### PR Summary Updates Identity and BlazorIdentity scaffolding templates (and their compiled `.cs`/`.tt` counterparts in both `VS.Web.CG.Mvc` and `dotnet-scaffold-aspnet` projects) to retrieve the user's stored email via `UserManager.GetEmailAsync(user)` before sending confirmation or password reset emails, throwing an `InvalidOperationException` if the stored email is null or empty. - `Account.ForgotPassword.cs.cshtml` and `ForgotPasswordModel.tt/.cs` (Bootstrap4/5 and `dotnet-scaffold-aspnet`): replaced `Input.Email` with `storedEmail` retrieved via `_userManager.GetEmailAsync(user)`, with null-check guard. - `Account.ResendEmailConfirmation.cs.cshtml` and `ResendEmailConfirmationModel.tt/.cs`: same pattern applied for email confirmation resending. - `BlazorIdentity/Pages/ForgotPassword.tt/.cs` and `ResendEmailConfirmation.tt/.cs` (both scaffolding projects): replaced `Input.Email` with `storedEmail` from `UserManager.GetEmailAsync(user)` before calling `EmailSender`. - Added consistent validation logic (`throw new InvalidOperationException("Users must have an email.")`) across all affected templates to prevent sending emails with missing addresses. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Co-authored-by: Dmitrii Korolev <[email protected]>
haileymck
pushed a commit
to dotnet/Scaffolding
that referenced
this pull request
Nov 13, 2026
A similar PR to dotnet/dotnet#10222 fixing scaffolding templates ---- #### AI description (iteration 1) #### PR Classification Bug fix: ensures identity templates send emails to the user's stored email address instead of the potentially unverified `Input.Email` value from the form. #### PR Summary This PR updates Identity scaffolding templates (MVC Bootstrap4/5 and Blazor) to retrieve the user's stored email via `UserManager.GetEmailAsync(user)` before sending confirmation or password reset emails, throwing an `InvalidOperationException` if no email is stored. - `Account.ForgotPassword.cs.cshtml` (Bootstrap4/5): use `storedEmail` instead of `Input.Email` when sending reset password email. - `Account.ResendEmailConfirmation.cs.cshtml` (Bootstrap4/5): use `storedEmail` instead of `Input.Email` when sending confirmation email. - `BlazorIdentity/Pages/ForgotPassword.tt` and corresponding generated `.cs` file: fetch and validate `storedEmail` before calling `EmailSender.SendPasswordResetLinkAsync`. - `BlazorIdentity/Pages/ResendEmailConfirmation.tt` and corresponding generated `.cs` file: fetch and validate `storedEmail` before calling `EmailSender.SendConfirmationLinkAsync`. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Co-authored-by: Dmitrii Korolev <[email protected]>
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.


Lookups a valid user email instead of using unvalidated user input.