]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 906745 - In MySQL, tokens are not case-sensitive, reducing total entropy and...
authorDave Lawrence <dlawrence@mozilla.com>
Wed, 16 Oct 2013 16:07:05 +0000 (12:07 -0400)
committerDave Lawrence <dlawrence@mozilla.com>
Wed, 16 Oct 2013 16:07:05 +0000 (12:07 -0400)
r=LpSolit,a=glob

Bugzilla/Token.pm
template/en/default/global/code-error.html.tmpl

index 264a28db132d1bbbacb397f3ea3b8adb8e77183a..a924324dca529385abc935a488077d9001d98de3 100644 (file)
@@ -258,13 +258,18 @@ sub Cancel {
 
     # Get information about the token being canceled.
     trick_taint($token);
-    my ($issuedate, $tokentype, $eventdata, $userid) =
-        $dbh->selectrow_array('SELECT ' . $dbh->sql_date_format('issuedate') . ',
+    my ($db_token, $issuedate, $tokentype, $eventdata, $userid) =
+        $dbh->selectrow_array('SELECT token, ' . $dbh->sql_date_format('issuedate') . ',
                                       tokentype, eventdata, userid
                                  FROM tokens
                                 WHERE token = ?',
                                 undef, $token);
 
+    # Some DBs such as MySQL are case-insensitive by default so we do
+    # a quick comparison to make sure the tokens are indeed the same.
+    (defined $db_token && $db_token eq $token)
+        || ThrowCodeError("cancel_token_does_not_exist");
+
     # If we are canceling the creation of a new user account, then there
     # is no entry in the 'profiles' table.
     my $user = new Bugzilla::User($userid);
@@ -329,10 +334,17 @@ sub GetTokenData {
     $token = clean_text($token);
     trick_taint($token);
 
-    return $dbh->selectrow_array(
-        "SELECT userid, " . $dbh->sql_date_format('issuedate') . ", eventdata, tokentype
-         FROM   tokens 
+    my @token_data = $dbh->selectrow_array(
+        "SELECT token, userid, " . $dbh->sql_date_format('issuedate') . ", eventdata, tokentype
+         FROM   tokens
          WHERE  token = ?", undef, $token);
+
+    # Some DBs such as MySQL are case-insensitive by default so we do
+    # a quick comparison to make sure the tokens are indeed the same.
+    my $db_token = shift @token_data;
+    return undef if (!defined $db_token || $db_token ne $token);
+
+    return @token_data;
 }
 
 # Deletes specified token
index 65a484b476f33b83756860fbd11be2dfa5367e0a..086f34ab62382edf4042b97666795630c4936386 100644 (file)
   [% ELSIF error == "token_generation_error" %]
     Something is seriously wrong with the token generation system.
 
+  [% ELSIF error == "cancel_token_does_not_exist" %]
+    The token to be cancelled does not exist.
+
   [% ELSIF error == "template_error" %]
     [% template_error_msg FILTER html %]