Last modified: 2013-09-04 11:53:06 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T37441, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 35441 - Email address confirmation broken due to incorrect or missing assignment of $expiration in User::confirmationToken()
Email address confirmation broken due to incorrect or missing assignment of $...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Email (Other open bugs)
1.17.x
All All
: High major with 3 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-24 01:31 UTC by Laurence 'GreenReaper' Parry
Modified: 2013-09-04 11:53 UTC (History)
6 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Fix for email confirmation token expiration setting in 1.17.3 (573 bytes, patch)
2012-03-24 01:31 UTC, Laurence 'GreenReaper' Parry
Details

Description Laurence 'GreenReaper' Parry 2012-03-24 01:31:15 UTC
Created attachment 10316 [details]
Fix for email confirmation token expiration setting in 1.17.3

The recent patches break email confirmation in 1.17.3 and likely break or degrade it on other versions. Here is the result of attempting to set email in 1.17.3:

Internal error
Non-string key given
Backtrace:
#0 [....]/w/includes/GlobalFunctions.php(781): MessageCache->get(NULL, true, Object(Language))
#1 [....]/w/includes/GlobalFunctions.php(902): wfMsgGetKey(NULL, true, Object(Language), false)
#2 [....]/w/languages/Language.php(513): wfMsgExt(NULL, Array)
#3 [....]/w/languages/Language.php(525): Language->getMessageFromDB(NULL)
#4 [....]/w/languages/Language.php(799): Language->getMonthName(false)
#5 [....]/w/languages/Language.php(1560): Language->sprintfDate('H:i, j F Y', false)
#6 [....]/w/includes/User.php(2966): Language->timeanddate('f4e8c51bf5ef375...', false)
#7 [....]/w/includes/specials/SpecialConfirmemail.php(84): User->sendConfirmationMail()
#8 [....]/w/includes/specials/SpecialConfirmemail.php(58): EmailConfirmation->showRequestForm()

This is because assignment of $expiration incorrectly falls through to the assignment of $token, which is not a valid date:

 function confirmationToken( &$expiration ) {
                $now = time();
                $expires = $now + 7 * 24 * 60 * 60;
                $expiration = 
                $token = MWCryptRand::generateHex( 32 );
                $hash = md5( $token );
                $this->load();
                $this->mEmailToken = $hash;
                $this->mEmailTokenExpires = wfTimestamp( TS_MW, $expires );
                return $token;
        }

The relevant section of the 1.17.3 patch is:

@@ -3005,12 +3009,12 @@
 	function confirmationToken( &$expiration ) {
 		$now = time();
 		$expires = $now + 7 * 24 * 60 * 60;
-		$expiration = wfTimestamp( TS_MW, $expires );
-		$token = self::generateToken( $this->mId . $this->mEmail . $expires );
+		$expiration = 
+		$token = MWCryptRand::generateHex( 32 );
 		$hash = md5( $token );
 		$this->load();
 		$this->mEmailToken = $hash;
-		$this->mEmailTokenExpires = $expiration;
+		$this->mEmailTokenExpires = wfTimestamp( TS_MW, $expires );
 		return $token;
 	}
 

It appears that this is an attempt to incorrectly optimize the setting of $expiration. This is backed up by the patch in 1.18.2, which removes access to the variable from the function:
@@ -3268,12 +3272,11 @@
 		global $wgUserEmailConfirmationTokenExpiry;
 		$now = time();
 		$expires = $now + $wgUserEmailConfirmationTokenExpiry;
-		$expiration = wfTimestamp( TS_MW, $expires );
-		$token = self::generateToken( $this->mId . $this->mEmail . $expires );
-		$hash = md5( $token );
 		$this->load();
+		$token = MWCryptRand::generateHex( 32 );
+		$hash = md5( $token );
 		$this->mEmailToken = $hash;
-		$this->mEmailTokenExpires = $expiration;
+		$this->mEmailTokenExpires = wfTimestamp( TS_MW, $expires );
 		return $token;
 	}
 

I have attached a patch to 1.17.3 that replaces $expiration and uses it to set $this->mEmailTokenExpires again. (It will be offset by a few lines on the branch due to other local patches.)

I do not have later versions around right now, but $expiration is likely still used by the parent function to display the expiry time in the email address, and so this should be fixed in 1.18, 1.19 and SVN. It might break the sending of the email, depending on the impact of $wgLang->{timeanddate|date|time}(null, false).
Comment 1 Sumana Harihareswara 2012-03-24 22:36:29 UTC
Thanks for the patch, Laurence.  By the way, we'd be happy to give you a Git account

https://www.mediawiki.org/wiki/Project:Labsconsole_accounts

so that you can submit this and other future patches directly if you want, and get them reviewed faster:

https://www.mediawiki.org/wiki/Git/Workflow#How_to_submit_a_patch
Comment 2 Tim Starling 2012-03-26 03:49:52 UTC
Yes, it also needs fixing in 1.18, 1.19 and trunk. Dantman, you're working on that, right?
Comment 3 Daniel Friesen 2012-03-26 04:39:25 UTC
Merged into trunk and about to be merged into the release branches:
https://gerrit.wikimedia.org/r/#q,project:mediawiki/core+topic:2012/emailconf-expiryfix,n,z
Comment 4 Laurence 'GreenReaper' Parry 2012-03-26 05:59:30 UTC
In 1.17, why call $this->load() twice? (It's there already, a few lines on.)
Comment 5 Daniel Friesen 2012-03-26 06:02:18 UTC
(In reply to comment #4)
> In 1.17, why call $this->load() twice? (It's there already, a few lines on.)

Gah... that was from the cherry pick. I'll submit a new patch set.
Comment 6 Sumana Harihareswara 2012-05-22 13:53:46 UTC
Daniel, were you able to submit a new patch set?
Comment 7 Daniel Friesen 2012-05-22 15:23:23 UTC
Oh right. This should already be fixed and released.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links