Skip to content

Fix Core Identity email lookup - #10222

Merged
wtgodbe merged 1 commit into
mainfrom
wtgodbe/port-4163dc5-main
Oct 14, 2026
Merged

wtgodbe merged 1 commit into
mainfrom
wtgodbe/port-4163dc5-main

Conversation

@wtgodbe

@wtgodbe wtgodbe commented Oct 14, 2026

Copy link
Copy Markdown
Member

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

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]>
@wtgodbe
wtgodbe requested review from DeagleGross and a balanced review from Copilot October 14, 2026 16:10
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team October 14, 2026 16:10
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Missing stored emails introduce inconsistent error responses and unhandled UI failures, while the UI behavior lacks regression coverage.

8 open findings
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.

@wtgodbe
wtgodbe merged commit d665156 into main Oct 14, 2026
12 checks passed
@wtgodbe
wtgodbe deleted the wtgodbe/port-4163dc5-main branch October 14, 2026 20:57
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]>
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.

3 participants