Repository navigation
Fix pre-account hijacks and harden account recovery - #1730
Open
BenjaminMichaelis wants to merge 2 commits into
Open
BenjaminMichaelis wants to merge 2 commits into
BenjaminMichaelis wants to merge 2 commits into
Conversation
Fixes the Identity findings from the 2026-11 security audit: - ExternalLogin: never link an external login to an account for an unverified, typed email. The login is recorded as pending and linked by ConfirmEmail only when the emailed link is opened in a browser that still holds that same external login. Adds the missing hCaptcha check, and deletes the account if recording the pending login fails. - Register: a password chosen at registration survives the first email confirmation only when the link is opened in the registering browser; otherwise it is removed and the mailbox owner chooses one. - ConfirmEmail (first confirmation) and ResetPassword: remove external logins, revoke MCP tokens and rotate the security stamp. ResetPassword also clears lockout. - ConfirmEmailChange: require the signed-in user to be the requester, and send a change-specific email. - Build email links from SiteSettings:BaseUrl instead of the Host header. - RegisterConfirmation: always render the generic page (no existence oracle). - Login: wrong passwords no longer lock accounts that have no password. Adds HTTP-level regression tests derived from the audit's reproductions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The HttpClient caller disposes it; fixes CodeQL cs/local-not-disposed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes the account-ownership findings from the recent security review. The common thread: a credential (password, external login, MCP token) or an email address could end up on an account before anyone proved they control that account's mailbox, and then survive the real owner confirming or resetting it.
Changes
External login registration (
ExternalLogin)AddLoginAsyncfor the typed (unverified) email. It records the external login as pending (inAspNetUserTokens), andConfirmEmaillinks it only when the emailed link is opened in a browser that still holds that same external login. A link opened anywhere else confirms the email but links nothing; the page tells the user to log in with the provider again, which sends a fresh link.Register / first email confirmation (
Register,ConfirmEmail)Password reset (
ResetPassword)Email change (
ConfirmEmailChange,Manage/Email)ConfirmEmailChangenow requires the signed-in user to be the account that requested the change (anonymous clicks go to the login page, and other users get an error).Email links
SiteSettings:BaseUrl(newUrl.EmailPageLinkhelper) instead of the requestHost.Other
RegisterConfirmationno longer looks the user up; it always renders the same generic page.Behavior changes to be aware of
Not changed:
AllowedHostsI did not narrow
AllowedHosts. The deploy workflow's smoke check callshttps://$FQDN/healthon the Container Apps default*.azurecontainerapps.iohostname, and container-app health probes may send aHostheader that isn't one of the public names. Restricting hosts inappsettings.jsoncould fail deployments or probes. With links now built fromSiteSettings:BaseUrl, the requestHostno longer affects emailed links. If you still want host filtering, it's safest to setAllowedHostsper environment in the Container App configuration, including the default FQDN.Tests
New HTTP-level tests in
EssentialCSharp.Web.Tests/Identity/drive the real pages with separate cookie jars per "browser" and capture outgoing email:ExternalLoginAccountLinkingTests: no link before confirmation; a pre-registered login doesn't survive confirm plus reset; linking in the same browser; no linking with a different external login; the other-browser recovery path; captcha required; legacy pre-linked logins removed.RegisterAccountOwnershipTests: a squatter's password is removed when the email is confirmed in another browser; the choose-a-password flow; the same-browser registrant keeps the password; reset removes logins and tokens and rotates the stamp.ConfirmEmailChangeTests: anonymous, other-user and requester clicks; change-specific email.AccountRecoveryHardeningTests: RegisterConfirmation oracle; forged-Hostreset and confirmation links; no lockout without a password; reset clears lockout.Against unmodified
main, 20 of the 23 new tests fail; the other 3 are positive controls. All 23 pass with this change.IdentityEmailFailureTestswas updated for the new constructor parameters and now also asserts that the external-login handler doesn't callAddLoginAsync.Full
EssentialCSharp.Web.Testsrun locally: 371/373 pass. The 2 failures (Layout_WithDefaultTestBackend_DoesNotRequestContextualSearch,McpCall_FindBookHelpForDiagnostic_ReturnsReadableTextAndStructuredContent) come from local AI user-secrets (an embedding call returns 401). They fail the same way on unmodifiedmain.Locally I built with SDK 10.0.204 because 10.0.403 isn't installed on this machine;
global.jsonis unchanged in the PR.🤖 Generated with Claude Code