Safety fixes for API:
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 3 Mar 2008 05:45:37 +0000 (05:45 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 3 Mar 2008 05:45:37 +0000 (05:45 +0000)
* drop user credentials for JSON callback output
* anticipating future changes, don't report anon edit tokens in JSON callback output

includes/api/ApiFormatJson.php
includes/api/ApiMain.php
includes/api/ApiQueryBase.php

index eae68fb..22ca658 100644 (file)
@@ -74,7 +74,7 @@ class ApiFormatJson extends ApiFormatBase {
 
        public function getParamDescription() {
                return array (
-                       'callback' => 'If specified, wraps the output into a given function call',
+                       'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
                );
        }
 
index f267c7e..0711a24 100644 (file)
@@ -118,6 +118,14 @@ class ApiMain extends ApiBase {
                        // If the current user cannot read, 
                        // Remove all modules other than login
                        global $wgUser;
+                       
+                       if( $request->getVal( 'callback' ) !== null ) {
+                               // JSON callback allows cross-site reads.
+                               // For safety, strip user credentials.
+                               wfDebug( "API: stripping user credentials for JSON callback\n" );
+                               $wgUser = new User();
+                       }
+                       
                        if (!$wgUser->isAllowed('read')) {
                                self::$Modules = array(
                                        'login'  => self::$Modules['login'],
index f964ea9..98a6ef3 100644 (file)
@@ -216,6 +216,10 @@ abstract class ApiQueryBase extends ApiBase {
        }
 
        public function getTokenFlag($tokenArr, $action) {
+               if ($this->getMain()->getRequest()->getVal('callback') !== null) {
+                       // Don't do any session-specific data.
+                       return false;
+               }
                if (in_array($action, $tokenArr)) {
                        global $wgUser;
                        if ($wgUser->isAllowed($action))