Repository navigation
fix(mailer): validate both addresses before sending email change mails - #2949
Open
montjeffrey wants to merge 1 commit into
Open
montjeffrey wants to merge 1 commit into
montjeffrey wants to merge 1 commit into
Conversation
EmailChangeMail sends the mail to the new address and the mail to the current address concurrently, and each address is validated inside Mail. When one of them fails validation the request is rejected and no token is stored, but the mail to the other address has already been sent. Validate every address before sending to any of them when the mail client validates addresses.
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.
What
Fixes #2948.
With secure email change on and the address check on,
PUT /user {"email": ...}from a user who already has an address sends two confirmation mails, one to the new address and one to the current one. When one of the two addresses fails the check, the request returns 400email_address_invalidand no token is stored, but the mail to the other address has already been sent. Its link can never be used.How
EmailChangeMailsends the two mails concurrently and each address is checked insideMail, so one check failing does not stop the other mail.mailer.Validator: a small interface for aClientthat checks an address before it sends to it.Mailalready runs.EmailChangeMailchecks every address before it starts sending, when it has more than one address and the client is aValidator.Nothing changes when the address check is off, when there is only one address, or with the Send Email hook.
Tests
New test
TestEmailChangeMailValidatesBeforeSendingininternal/mailer/templatemailer: new address rejected, current address rejected, both accepted, each with a test client and with the real validating client.master(10ef107) it fails: with the test client both rejected cases report one mail sent where none is expected. With the real client the result depends on timing there (one of the two rejected cases failed in my run).go test -p 1 ./internal/api/... ./internal/mailer/... -count=1 -v: 1,545 pass and 3 fail, against 1,538 pass and 3 fail onmaster. The difference is the 7 new results. The 3 failures areTestAuth/TestMaybeLoadUserOrSession/Valid_Session_ID_Claimand its two parents, which fail the same way onmasterin my container (atime.Locationdifference).gofmt -s -l .prints nothing;make vet,make staticandmake secpass.Over HTTP, against a server built from each tree, with a local mail catcher as the SMTP server (mails received):
master10ef107Not run: the race detector (my image builds with
CGO_ENABLED=0),make testas CI runs it, a hosted project.Left as it is
Mail. That is up to two more DNS lookups, or two more calls to the validation service, for a secure email change. The first check runs one address after the other.GOTRUE_MAILER_EMAIL_BACKGROUND_SENDING) nothing changes: the background client is not aValidator, and in that mode the check result does not reach the request anyway.GOTRUE_RATE_LIMIT_EMAIL_SENT, as before.#2889 changes how the list of addresses in the same function is built. The two changes do not touch the same lines.
I used an AI assistant (Claude Code) to read the code and help write the change, the test and this description. I ran the tests and the requests on my own machine and checked the output.