SECURITY: API: Use constant-time comparison for watchlist token
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 27 Mar 2015 15:49:58 +0000 (11:49 -0400)
committerChad Horohoe <chadh@wikimedia.org>
Tue, 11 Aug 2015 14:16:57 +0000 (07:16 -0700)
Avoids a theoretical timing attack.

Bug: T94116
Change-Id: Ia4a2b13bd5d3cd256c6b2deada224148dc2888a6

includes/api/ApiBase.php

index 393ff49..754c0ed 100644 (file)
@@ -1229,7 +1229,7 @@ abstract class ApiBase extends ContextSource {
                                $this->dieUsage( 'Specified user does not exist', 'bad_wlowner' );
                        }
                        $token = $user->getOption( 'watchlisttoken' );
-                       if ( $token == '' || $token != $params['token'] ) {
+                       if ( $token == '' || !hash_equals( $token, $params['token'] ) ) {
                                $this->dieUsage(
                                        'Incorrect watchlist token provided -- please set a correct token in Special:Preferences',
                                        'bad_wltoken'