BREAKING CHANGE: Require POST for patrolling revisions and salt the patrol token...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 9 Dec 2010 21:29:03 +0000 (21:29 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 9 Dec 2010 21:29:03 +0000 (21:29 +0000)
See my comments on r75274, for which this is a follow-up. Using a dedicated, but constant patrol token is in my opinion the optimal compromise between performance (only require fetching the token once) and security (leaking the token will only compromise the patrolling feature).

includes/api/ApiPatrol.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryRecentChanges.php

index ddc205f..04afd1d 100644 (file)
@@ -59,6 +59,10 @@ class ApiPatrol extends ApiBase {
                $this->getResult()->addValue( null, $this->getModuleName(), $result );
        }
 
+       public function mustBePosted() {
+               return true;
+       }
+
        public function isWriteMode() {
                return true;
        }
@@ -95,8 +99,7 @@ class ApiPatrol extends ApiBase {
        }
 
        public function getTokenSalt() {
-               $params = $this->extractRequestParams();
-               return $params['rcid'];
+               return 'patrol';
        }
 
        protected function getExamples() {
index 8ffb2e2..3156b7e 100644 (file)
@@ -87,6 +87,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
                        'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
                        'import' => array( 'ApiQueryInfo', 'getImportToken' ),
+                       'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ),
                );
                wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) );
                return $this->tokenFunctions;
index 2e9f9b7..2aecea8 100644 (file)
@@ -79,7 +79,13 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        return false;
                }
 
-               return $wgUser->editToken( $rc->getAttribute( 'rc_id' ) );
+               // The patrol token is always the same, let's exploit that
+               static $cachedPatrolToken = null;
+               if ( is_null( $cachedPatrolToken ) ) {
+                       $cachedPatrolToken = $wgUser->editToken( 'patrol' );
+               }
+               
+               return $cachedPatrolToken;
        }
 
        /**