summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Token.pm
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2015-09-06 12:41:31 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2015-09-06 12:41:31 +0200
commit23807179790108fc2575d06df59dbaebf8ce0af8 (patch)
treeed9e1b383de7f72f1892c66552640240c431f5f2 /Bugzilla/Token.pm
parenta666b2a74f565a5ebb38f0ce0b400d04b1ea7ca4 (diff)
downloadbugzilla-23807179790108fc2575d06df59dbaebf8ce0af8.tar.gz
bugzilla-23807179790108fc2575d06df59dbaebf8ce0af8.tar.xz
Bug 1194987: Editing your email address and make it point to a non-existent email address makes Bugzilla stop working
r=gerv a=sgreen
Diffstat (limited to 'Bugzilla/Token.pm')
-rw-r--r--Bugzilla/Token.pm52
1 files changed, 29 insertions, 23 deletions
diff --git a/Bugzilla/Token.pm b/Bugzilla/Token.pm
index 67a201b53..be76be645 100644
--- a/Bugzilla/Token.pm
+++ b/Bugzilla/Token.pm
@@ -34,6 +34,8 @@ use parent qw(Exporter);
# 62 = 0-9, a-z, A-Z.
use constant TOKEN_LENGTH => 22;
+use constant SEND_NOW => 1;
+
################################################################################
# Public Functions
################################################################################
@@ -122,43 +124,49 @@ sub issue_new_user_account_token {
# who made the request, and so it is reasonable to send the email in the same
# language used to view the "Create a New Account" page (we cannot use their
# user prefs as the user has no account yet!).
- MessageToMTA($message);
+ MessageToMTA($message, SEND_NOW);
}
sub IssueEmailChangeToken {
- my ($user, $new_email) = @_;
- my $email_suffix = Bugzilla->params->{'emailsuffix'};
- my $old_email = $user->login;
-
- my ($token, $token_ts) = _create_token($user->id, 'emailold', $old_email . ":" . $new_email);
+ my $new_email = shift;
+ my $user = Bugzilla->user;
- my $newtoken = _create_token($user->id, 'emailnew', $old_email . ":" . $new_email);
+ my ($token, $token_ts) = _create_token($user->id, 'emailold', $user->login . ":$new_email");
+ my $newtoken = _create_token($user->id, 'emailnew', $user->login . ":$new_email");
# Mail the user the token along with instructions for using it.
my $template = Bugzilla->template_inner($user->setting('lang'));
my $vars = {};
- $vars->{'oldemailaddress'} = $old_email . $email_suffix;
- $vars->{'newemailaddress'} = $new_email . $email_suffix;
+ $vars->{'newemailaddress'} = $new_email . Bugzilla->params->{'emailsuffix'};
$vars->{'expiration_ts'} = ctime($token_ts + MAX_TOKEN_AGE * 86400);
- $vars->{'token'} = $token;
- $vars->{'emailaddress'} = $old_email . $email_suffix;
+
+ # First send an email to the new address. If this one doesn't exist,
+ # then the whole process must stop immediately. This means the email must
+ # be sent immediately and must not be stored in the queue.
+ $vars->{'token'} = $newtoken;
my $message;
- $template->process("account/email/change-old.txt.tmpl", $vars, \$message)
+ $template->process('account/email/change-new.txt.tmpl', $vars, \$message)
|| ThrowTemplateError($template->error());
- MessageToMTA($message);
+ MessageToMTA($message, SEND_NOW);
- $vars->{'token'} = $newtoken;
- $vars->{'emailaddress'} = $new_email . $email_suffix;
+ # If we come here, then the new address exists. We now email the current
+ # address, but we don't want to stop the process if it no longer exists,
+ # to give a chance to the user to confirm the email address change.
+ $vars->{'token'} = $token;
- $message = "";
- $template->process("account/email/change-new.txt.tmpl", $vars, \$message)
+ $message = '';
+ $template->process('account/email/change-old.txt.tmpl', $vars, \$message)
|| ThrowTemplateError($template->error());
- MessageToMTA($message);
+ eval { MessageToMTA($message, SEND_NOW); };
+
+ # Give the user a chance to cancel the process even if he never got
+ # the email above. The token is required.
+ return $token;
}
# Generates a random token, adds it to the tokens table, and sends it
@@ -543,17 +551,15 @@ Bugzilla::Token - Provides different routines to manage tokens.
Returns: Nothing. It throws an error if the same user made the same
request in the last few minutes.
-=item C<sub IssueEmailChangeToken($user, $new_email)>
+=item C<sub IssueEmailChangeToken($new_email)>
Description: Sends two distinct tokens per email to the old and new email
addresses to confirm the email address change for the given
user. These tokens remain valid for the next MAX_TOKEN_AGE days.
- Params: $user - User object of the user requesting a new
- email address.
- $new_email - The new email address of the user.
+ Params: $new_email - The new email address of the user.
- Returns: Nothing.
+ Returns: The token to cancel the request.
=item C<IssuePasswordToken($user)>