Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions internal/api/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,17 @@ func (a *API) verifyPost(w http.ResponseWriter, r *http.Request, params *VerifyP
if isUsingTokenHash(params) {
user, terr = a.verifyTokenHash(tx, params)
} else {
user, terr = a.verifyUserAndToken(tx, params, aud)
var sessionUser *models.User
if params.Type == phoneChangeVerification {
// phone_change has no unique constraint, so a lookup by phone
// can match an abandoned pending change from another user.
// Prefer the authenticated session user when their pending
// change matches the phone being verified.
if authCtx, aerr := a.requireAuthentication(w, r); aerr == nil {
sessionUser = getUser(authCtx)
}
}
user, terr = a.verifyUserAndToken(tx, params, aud, sessionUser)
}
if terr != nil {
return terr
Expand Down Expand Up @@ -696,7 +706,7 @@ func (a *API) verifyTokenHash(conn *storage.Connection, params *VerifyParams) (*
}

// verifyUserAndToken verifies the token associated to the user based on the verify type
func (a *API) verifyUserAndToken(conn *storage.Connection, params *VerifyParams, aud string) (*models.User, error) {
func (a *API) verifyUserAndToken(conn *storage.Connection, params *VerifyParams, aud string, sessionUser *models.User) (*models.User, error) {
config := a.config

var user *models.User
Expand All @@ -705,7 +715,11 @@ func (a *API) verifyUserAndToken(conn *storage.Connection, params *VerifyParams,

switch params.Type {
case phoneChangeVerification:
user, err = models.FindUserByPhoneChangeAndAudience(conn, params.Phone, aud)
if sessionUser != nil && sessionUser.PhoneChange == params.Phone {
user = sessionUser
} else {
user, err = models.FindUserByPhoneChangeAndAudience(conn, params.Phone, aud)
}
case smsVerification:
user, err = models.FindUserByPhoneAndAudience(conn, params.Phone, aud)
case mail.EmailChangeVerification:
Expand Down
Loading