https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114429
Revision: 114429
Author: reedy
Date: 2012-03-22 19:43:00 +0000 (Thu, 22 Mar 2012)
Log Message:
-----------
* (bug 34212) ApiBlock/ApiUnblock allow action to take place without a token
parameter present
* (bug 35317) CSRF in Special:Upload
Revert r56793, which removed the CSRF check for Special:Upload for normal file
uploads. Cross-site posting of file uploads without user interaction has been
possible since at least as early as Chrome 8 (late 2010) and Firefox 6 (mid
2011).
Commonist has used api.php since version 0.4.0 (April 2010), and the API
already requires an edit token, so Commonist 0.4.0+ is not affected by this
change.
* (bug 34907) Fix for CSRF vulnerability due to mw.user.tokens. Patch by Roan
Kattouw and Tim Starling.
* Filter out private modules early in ResourceLoader::makeResponse() and just
pretend they weren't specified. This means these modules cannot be loaded
through load.php . This filtering must not happen in makeModuleResponse(),
because that would break inlining.
* Force inlining of private modules in OutputPage::makeResourceLoaderLink(),
disregarding $wgResourceLoaderInlinePrivateModules
* Remove $wgResourceLoaderInlinePrivateModules
* Remove special treatment of private modules ($private) in
ResourceLoader::makeResponse() and sendResponseHeaders(), because we're not
allowing private modules to be loaded through here any more
* Remove identity checks in ResourceLoaderUserOptionsModule and
ResourceLoaderUserCSSPrefsModule, they didn't make a lot of sense before but
they're certainly useless now.
* Factored out error comment construction in ResourceLoader.php and stripped
comment terminations from exception messages. I didn't find an XSS
vulnerability but it looked scary.
* (bug 35315) XSS in CharInsert, forged strip markers
Modified Paths:
--------------
branches/wmf/1.19wmf1/extensions/CharInsert/CharInsert.php
branches/wmf/1.19wmf1/includes/AutoLoader.php
branches/wmf/1.19wmf1/includes/DefaultSettings.php
branches/wmf/1.19wmf1/includes/GlobalFunctions.php
branches/wmf/1.19wmf1/includes/OutputPage.php
branches/wmf/1.19wmf1/includes/User.php
branches/wmf/1.19wmf1/includes/api/ApiMain.php
branches/wmf/1.19wmf1/includes/installer/Installer.php
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoader.php
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserOptionsModule.php
branches/wmf/1.19wmf1/includes/specials/SpecialUpload.php
branches/wmf/1.19wmf1/includes/specials/SpecialUserlogin.php
branches/wmf/1.19wmf1/includes/specials/SpecialWatchlist.php
Added Paths:
-----------
branches/wmf/1.19wmf1/includes/CryptRand.php
Property Changed:
----------------
branches/wmf/1.19wmf1/
branches/wmf/1.19wmf1/includes/
branches/wmf/1.19wmf1/includes/AutoLoader.php
branches/wmf/1.19wmf1/includes/GlobalFunctions.php
branches/wmf/1.19wmf1/includes/User.php
branches/wmf/1.19wmf1/includes/specials/
branches/wmf/1.19wmf1/includes/specials/SpecialWatchlist.php
Property changes on: branches/wmf/1.19wmf1
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JSTesting:100352-107913
/branches/REL1_15/phase3:51646
/branches/REL1_17/phase3:81445,81448
/branches/new-installer/phase3:43664-66004
/branches/sqlite:58211-58321
/branches/wmf/1.18wmf1:97508,111667
/trunk/phase3:111002,111029,111034,111062,111067,111076,111085,111128,111144,111251,111397,111427,111571,111574,111597,111647,111658,111673,111695,111697,111750,111795,111802-111803,111827,111881,111920,111965-111967,112021,112034,112037,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112100,112128,112132-112133,112141,112152,112169-112170,112172-112173,112179,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112533-112534,112563,112566,112573,112700,112750,112839-112840,112843,112855,112866,112918,112951,112995,113039,113085,113099,113169,113171,113195,113214,113268,113312,113394,113412,113415,113617,113710,113727,113737,113775,113816,113892,114228
+ /branches/JSTesting:100352-107913
/branches/REL1_15/phase3:51646
/branches/REL1_17/phase3:81445,81448
/branches/REL1_19/phase3:114241,114283,114355
/branches/new-installer/phase3:43664-66004
/branches/sqlite:58211-58321
/branches/wmf/1.18wmf1:97508,111667
/trunk/phase3:111002,111029,111034,111062,111067,111076,111085,111128,111144,111251,111397,111427,111571,111574,111597,111647,111658,111673,111695,111697,111750,111795,111802-111803,111827,111881,111920,111965-111967,112021,112034,112037,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112100,112128,112132-112133,112141,112152,112169-112170,112172-112173,112179,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112533-112534,112563,112566,112573,112700,112750,112839-112840,112843,112855,112866,112918,112951,112995,113039,113085,113099,113169,113171,113195,113214,113268,113312,113394,113412,113415,113617,113710,113727,113737,113775,113816,113892,114228
Modified: branches/wmf/1.19wmf1/extensions/CharInsert/CharInsert.php
===================================================================
--- branches/wmf/1.19wmf1/extensions/CharInsert/CharInsert.php 2012-03-22
19:00:08 UTC (rev 114428)
+++ branches/wmf/1.19wmf1/extensions/CharInsert/CharInsert.php 2012-03-22
19:43:00 UTC (rev 114429)
@@ -49,7 +49,8 @@
return true;
}
-function charInsert( $data ) {
+function charInsert( $data, $params, $parser ) {
+ $data = $parser->mStripState->unstripBoth( $data );
return implode( "<br />\n",
array_map( 'charInsertLine',
explode( "\n", trim( $data ) ) ) );
Property changes on: branches/wmf/1.19wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JSTesting/includes:100352-107913
/branches/REL1_15/phase3/includes:51646
/branches/new-installer/phase3/includes:43664-66004
/branches/sqlite/includes:58211-58321
/branches/wmf/1.18wmf1/includes:97508,111667
/branches/wmf-deployment/includes:53381
/trunk/phase3/includes:111029,111034,111067,111085,111128,111144,111251,111397,111427,111571,111574,111597,111647,111658,111673,111695,111697,111750,111827,111965-111967,112021,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112128,112132-112133,112152,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112534,112563,112700,112839-112840,112843,112855,112866,112918,112951,112995,113099,113169,113171,113195,113214,113312,113394,113412,113415,113441,113617,113710,113727,113737,113816,113892,114228
+ /branches/JSTesting/includes:100352-107913
/branches/REL1_15/phase3/includes:51646
/branches/REL1_19/phase3/includes:114241,114283,114355
/branches/new-installer/phase3/includes:43664-66004
/branches/sqlite/includes:58211-58321
/branches/wmf/1.18wmf1/includes:97508,111667
/branches/wmf-deployment/includes:53381
/trunk/phase3/includes:111029,111034,111067,111085,111128,111144,111251,111397,111427,111571,111574,111597,111647,111658,111673,111695,111697,111750,111827,111965-111967,112021,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112128,112132-112133,112152,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112534,112563,112700,112839-112840,112843,112855,112866,112918,112951,112995,113099,113169,113171,113195,113214,113312,113394,113412,113415,113441,113617,113710,113727,113737,113816,113892,114228
Modified: branches/wmf/1.19wmf1/includes/AutoLoader.php
===================================================================
--- branches/wmf/1.19wmf1/includes/AutoLoader.php 2012-03-22 19:00:08 UTC
(rev 114428)
+++ branches/wmf/1.19wmf1/includes/AutoLoader.php 2012-03-22 19:43:00 UTC
(rev 114429)
@@ -49,6 +49,7 @@
'ConfEditorToken' => 'includes/ConfEditor.php',
'Cookie' => 'includes/Cookie.php',
'CookieJar' => 'includes/Cookie.php',
+ 'MWCryptRand' => 'includes/CryptRand.php',
'CurlHttpRequest' => 'includes/HttpFunctions.php',
'DeferrableUpdate' => 'includes/DeferredUpdates.php',
'DeferredUpdates' => 'includes/DeferredUpdates.php',
Property changes on: branches/wmf/1.19wmf1/includes/AutoLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/FileBackend/phase3/includes/AutoLoader.php:99972-106750
/branches/JSTesting/includes/AutoLoader.php:100352-107913
/branches/REL1_15/phase3/includes/AutoLoader.php:51646
/branches/REL1_17/phase3/includes/AutoLoader.php:81448
/branches/new-installer/phase3/includes/AutoLoader.php:43664-66004
/branches/sqlite/includes/AutoLoader.php:58211-58321
/branches/uploadwizard/phase3/includes/AutoLoader.php:73550-75905
/branches/wmf/1.19wmf1/includes/AutoLoader.php:112313
/branches/wmf-deployment/includes/AutoLoader.php:53381
/trunk/phase3/includes/AutoLoader.php:111029,111034,111067,111085,111128,111144,112313
+ /branches/FileBackend/phase3/includes/AutoLoader.php:99972-106750
/branches/JSTesting/includes/AutoLoader.php:100352-107913
/branches/REL1_15/phase3/includes/AutoLoader.php:51646
/branches/REL1_17/phase3/includes/AutoLoader.php:81448
/branches/REL1_19/phase3/includes/AutoLoader.php:114241,114283,114355
/branches/new-installer/phase3/includes/AutoLoader.php:43664-66004
/branches/sqlite/includes/AutoLoader.php:58211-58321
/branches/uploadwizard/phase3/includes/AutoLoader.php:73550-75905
/branches/wmf/1.19wmf1/includes/AutoLoader.php:112313
/branches/wmf-deployment/includes/AutoLoader.php:53381
/trunk/phase3/includes/AutoLoader.php:111029,111034,111067,111085,111128,111144,112313
Copied: branches/wmf/1.19wmf1/includes/CryptRand.php (from rev 114241,
branches/REL1_19/phase3/includes/CryptRand.php)
===================================================================
--- branches/wmf/1.19wmf1/includes/CryptRand.php
(rev 0)
+++ branches/wmf/1.19wmf1/includes/CryptRand.php 2012-03-22 19:43:00 UTC
(rev 114429)
@@ -0,0 +1,463 @@
+<?php
+/**
+ * A cryptographic random generator class used for generating secret keys
+ *
+ * This is based in part on Drupal code as well as what we used in our own code
+ * prior to introduction of this class.
+ *
+ * @author Daniel Friesen
+ * @file
+ */
+
+class MWCryptRand {
+
+ /**
+ * Minimum number of iterations we want to make in our drift
calculations.
+ */
+ const MIN_ITERATIONS = 1000;
+
+ /**
+ * Number of milliseconds we want to spend generating each separate byte
+ * of the final generated bytes.
+ * This is used in combination with the hash length to determine the
duration
+ * we should spend doing drift calculations.
+ */
+ const MSEC_PER_BYTE = 0.5;
+
+ /**
+ * Singleton instance for public use
+ */
+ protected static $singleton = null;
+
+ /**
+ * The hash algorithm being used
+ */
+ protected $algo = null;
+
+ /**
+ * The number of bytes outputted by the hash algorithm
+ */
+ protected $hashLength = null;
+
+ /**
+ * A boolean indicating whether the previous random generation was done
using
+ * cryptographically strong random number generator or not.
+ */
+ protected $strong = null;
+
+ /**
+ * Initialize an initial random state based off of whatever we can find
+ */
+ protected function initialRandomState() {
+ // $_SERVER contains a variety of unstable user and system
specific information
+ // It'll vary a little with each page, and vary even more with
separate users
+ // It'll also vary slightly across different machines
+ $state = serialize( $_SERVER );
+
+ // To try and vary the system information of the state a bit
more
+ // by including the system's hostname into the state
+ $state .= wfHostname();
+
+ // Try to gather a little entropy from the different php rand
sources
+ $state .= rand() . uniqid( mt_rand(), true );
+
+ // Include some information about the filesystem's current
state in the random state
+ $files = array();
+ // We know this file is here so grab some info about ourself
+ $files[] = __FILE__;
+ // The config file is likely the most often edited file we know
should be around
+ // so if the constant with it's location is defined include
it's stat info into the state
+ if ( defined( 'MW_CONFIG_FILE' ) ) {
+ $files[] = MW_CONFIG_FILE;
+ }
+ foreach ( $files as $file ) {
+ wfSuppressWarnings();
+ $stat = stat( $file );
+ wfRestoreWarnings();
+ if ( $stat ) {
+ // stat() duplicates data into numeric and
string keys so kill off all the numeric ones
+ foreach ( $stat as $k => $v ) {
+ if ( is_numeric( $k ) ) {
+ unset( $k );
+ }
+ }
+ // The absolute filename itself will differ
from install to install so don't leave it out
+ $state .= realpath( $file );
+ $state .= implode( '', $stat );
+ } else {
+ // The fact that the file isn't there is worth
at least a
+ // minuscule amount of entropy.
+ $state .= '0';
+ }
+ }
+
+ // Try and make this a little more unstable by including the
varying process
+ // id of the php process we are running inside of if we are
able to access it
+ if ( function_exists( 'getmypid' ) ) {
+ $state .= getmypid();
+ }
+
+ // If available try to increase the instability of the data by
throwing in
+ // the precise amount of memory that we happen to be using at
the moment.
+ if ( function_exists( 'memory_get_usage' ) ) {
+ $state .= memory_get_usage( true );
+ }
+
+ // It's mostly worthless but throw the wiki's id into the data
for a little more variance
+ $state .= wfWikiID();
+
+ // If we have a secret key or proxy key set then throw it into
the state as well
+ global $wgSecretKey, $wgProxyKey;
+ if ( $wgSecretKey ) {
+ $state .= $wgSecretKey;
+ } elseif ( $wgProxyKey ) {
+ $state .= $wgProxyKey;
+ }
+
+ return $state;
+ }
+
+ /**
+ * Randomly hash data while mixing in clock drift data for randomness
+ *
+ * @param $data The data to randomly hash.
+ * @return String The hashed bytes
+ * @author Tim Starling
+ */
+ protected function driftHash( $data ) {
+ // Minimum number of iterations (to avoid slow operations
causing the loop to gather little entropy)
+ $minIterations = self::MIN_ITERATIONS;
+ // Duration of time to spend doing calculations (in seconds)
+ $duration = ( self::MSEC_PER_BYTE / 1000 ) *
$this->hashLength();
+ // Create a buffer to use to trigger memory operations
+ $bufLength = 10000000;
+ $buffer = str_repeat( ' ', $bufLength );
+ $bufPos = 0;
+
+ // Iterate for $duration seconds or at least $minIerations
number of iterations
+ $iterations = 0;
+ $startTime = microtime( true );
+ $currentTime = $startTime;
+ while ( $iterations < $minIterations || $currentTime -
$startTime < $duration ) {
+ // Trigger some memory writing to trigger some bus
activity
+ // This may create variance in the time between
iterations
+ $bufPos = ( $bufPos + 13 ) % $bufLength;
+ $buffer[$bufPos] = ' ';
+ // Add the drift between this iteration and the last in
as entropy
+ $nextTime = microtime( true );
+ $delta = (int)( ( $nextTime - $currentTime ) * 1000000
);
+ $data .= $delta;
+ // Every 100 iterations hash the data and entropy
+ if ( $iterations % 100 === 0 ) {
+ $data = sha1( $data );
+ }
+ $currentTime = $nextTime;
+ $iterations++;
+ }
+ $timeTaken = $currentTime - $startTime;
+ $data = $this->hash( $data );
+
+ wfDebug( __METHOD__ . ": Clock drift calculation " .
+ "(time-taken=" . ( $timeTaken * 1000 ) . "ms, " .
+ "iterations=$iterations, " .
+ "time-per-iteration=" . ( $timeTaken / $iterations *
1e6 ) . "us)\n" );
+ return $data;
+ }
+
+ /**
+ * Return a rolling random state initially build using data from
unstable sources
+ * @return A new weak random state
+ */
+ protected function randomState() {
+ static $state = null;
+ if ( is_null( $state ) ) {
+ // Initialize the state with whatever unstable data we
can find
+ // It's important that this data is hashed right
afterwards to prevent
+ // it from being leaked into the output stream
+ $state = $this->hash( $this->initialRandomState() );
+ }
+ // Generate a new random state based on the initial random
state or previous
+ // random state by combining it with clock drift
+ $state = $this->driftHash( $state );
+ return $state;
+ }
+
+ /**
+ * Decide on the best acceptable hash algorithm we have available for
hash()
+ * @return String A hash algorithm
+ */
+ protected function hashAlgo() {
+ if ( !is_null( $this->algo ) ) {
+ return $this->algo;
+ }
+
+ $algos = hash_algos();
+ $preference = array( 'whirlpool', 'sha256', 'sha1', 'md5' );
+
+ foreach ( $preference as $algorithm ) {
+ if ( in_array( $algorithm, $algos ) ) {
+ $this->algo = $algorithm;
+ wfDebug( __METHOD__ . ": Using the
{$this->algo} hash algorithm.\n" );
+ return $this->algo;
+ }
+ }
+
+ // We only reach here if no acceptable hash is found in the
list, this should
+ // be a technical impossibility since most of php's hash list
is fixed and
+ // some of the ones we list are available as their own native
functions
+ // But since we already require at least 5.2 and hash() was
default in
+ // 5.1.2 we don't bother falling back to methods like sha1 and
md5.
+ throw new MWException( "Could not find an acceptable hashing
function in hash_algos()" );
+ }
+
+ /**
+ * Return the byte-length output of the hash algorithm we are
+ * using in self::hash and self::hmac.
+ *
+ * @return int Number of bytes the hash outputs
+ */
+ protected function hashLength() {
+ if ( is_null( $this->hashLength ) ) {
+ $this->hashLength = strlen( $this->hash( '' ) );
+ }
+ return $this->hashLength;
+ }
+
+ /**
+ * Generate an acceptably unstable one-way-hash of some text
+ * making use of the best hash algorithm that we have available.
+ *
+ * @return String A raw hash of the data
+ */
+ protected function hash( $data ) {
+ return hash( $this->hashAlgo(), $data, true );
+ }
+
+ /**
+ * Generate an acceptably unstable one-way-hmac of some text
+ * making use of the best hash algorithm that we have available.
+ *
+ * @return String A raw hash of the data
+ */
+ protected function hmac( $data, $key ) {
+ return hash_hmac( $this->hashAlgo(), $data, $key, true );
+ }
+
+ /**
+ * @see self::wasStrong()
+ */
+ public function realWasStrong() {
+ if ( is_null( $this->strong ) ) {
+ throw new MWException( __METHOD__ . ' called before
generation of random data' );
+ }
+ return $this->strong;
+ }
+
+ /**
+ * @see self::generate()
+ */
+ public function realGenerate( $bytes, $forceStrong = false ) {
+ wfProfileIn( __METHOD__ );
+
+ wfDebug( __METHOD__ . ": Generating cryptographic random bytes
for " . wfGetAllCallers( 5 ) . "\n" );
+
+ $bytes = floor( $bytes );
+ static $buffer = '';
+ if ( is_null( $this->strong ) ) {
+ // Set strength to false initially until we know what
source data is coming from
+ $this->strong = true;
+ }
+
+ if ( strlen( $buffer ) < $bytes ) {
+ // If available make use of mcrypt_create_iv URANDOM
source to generate randomness
+ // On unix-like systems this reads from /dev/urandom
but does it without any buffering
+ // and bypasses openbasdir restrictions so it's
preferable to reading directly
+ // On Windows starting in PHP 5.3.0 Windows' native
CryptGenRandom is used to generate
+ // entropy so this is also preferable to just trying to
read urandom because it may work
+ // on Windows systems as well.
+ if ( function_exists( 'mcrypt_create_iv' ) ) {
+ wfProfileIn( __METHOD__ . '-mcrypt' );
+ $rem = $bytes - strlen( $buffer );
+ $iv = mcrypt_create_iv( $rem,
MCRYPT_DEV_URANDOM );
+ if ( $iv === false ) {
+ wfDebug( __METHOD__ . ":
mcrypt_create_iv returned false.\n" );
+ } else {
+ $bytes .= $iv;
+ wfDebug( __METHOD__ . ":
mcrypt_create_iv generated " . strlen( $iv ) . " bytes of randomness.\n" );
+ }
+ wfProfileOut( __METHOD__ . '-mcrypt' );
+ }
+ }
+
+ if ( strlen( $buffer ) < $bytes ) {
+ // If available make use of openssl's
random_pesudo_bytes method to attempt to generate randomness.
+ // However don't do this on Windows with PHP < 5.3.4
due to a bug:
+ //
http://stackoverflow.com/questions/1940168/openssl-random-pseudo-bytes-is-slow-php
+ if ( function_exists( 'openssl_random_pseudo_bytes' )
+ && ( !wfIsWindows() || version_compare(
PHP_VERSION, '5.3.4', '>=' ) )
+ ) {
+ wfProfileIn( __METHOD__ . '-openssl' );
+ $rem = $bytes - strlen( $buffer );
+ $openssl_bytes = openssl_random_pseudo_bytes(
$rem, $openssl_strong );
+ if ( $openssl_bytes === false ) {
+ wfDebug( __METHOD__ . ":
openssl_random_pseudo_bytes returned false.\n" );
+ } else {
+ $buffer .= $openssl_bytes;
+ wfDebug( __METHOD__ . ":
openssl_random_pseudo_bytes generated " . strlen( $openssl_bytes ) . " bytes of
" . ( $openssl_strong ? "strong" : "weak" ) . " randomness.\n" );
+ }
+ if ( strlen( $buffer ) >= $bytes ) {
+ // openssl tells us if the random
source was strong, if some of our data was generated
+ // using it use it's say on whether the
randomness is strong
+ $this->strong = !!$openssl_strong;
+ }
+ wfProfileOut( __METHOD__ . '-openssl' );
+ }
+ }
+
+ // Only read from urandom if we can control the buffer size or
were passed forceStrong
+ if ( strlen( $buffer ) < $bytes && ( function_exists(
'stream_set_read_buffer' ) || $forceStrong ) ) {
+ wfProfileIn( __METHOD__ . '-fopen-urandom' );
+ $rem = $bytes - strlen( $buffer );
+ if ( !function_exists( 'stream_set_read_buffer' ) &&
$forceStrong ) {
+ wfDebug( __METHOD__ . ": Was forced to read
from /dev/urandom without control over the buffer size.\n" );
+ }
+ // /dev/urandom is generally considered the best
possible commonly
+ // available random source, and is available on most
*nix systems.
+ wfSuppressWarnings();
+ $urandom = fopen( "/dev/urandom", "rb" );
+ wfRestoreWarnings();
+
+ // Attempt to read all our random data from urandom
+ // php's fread always does buffered reads based on the
stream's chunk_size
+ // so in reality it will usually read more than the
amount of data we're
+ // asked for and not storing that risks depleting the
system's random pool.
+ // If stream_set_read_buffer is available set the
chunk_size to the amount
+ // of data we need. Otherwise read 8k, php's default
chunk_size.
+ if ( $urandom ) {
+ // php's default chunk_size is 8k
+ $chunk_size = 1024 * 8;
+ if ( function_exists( 'stream_set_read_buffer'
) ) {
+ // If possible set the chunk_size to
the amount of data we need
+ stream_set_read_buffer( $urandom, $rem
);
+ $chunk_size = $rem;
+ }
+ $random_bytes = fread( $urandom, max(
$chunk_size, $rem ) );
+ $buffer .= $random_bytes;
+ fclose( $urandom );
+ wfDebug( __METHOD__ . ": /dev/urandom generated
" . strlen( $random_bytes ) . " bytes of randomness.\n" );
+ if ( strlen( $buffer ) >= $bytes ) {
+ // urandom is always strong, set to
true if all our data was generated using it
+ $this->strong = true;
+ }
+ } else {
+ wfDebug( __METHOD__ . ": /dev/urandom could not
be opened.\n" );
+ }
+ wfProfileOut( __METHOD__ . '-fopen-urandom' );
+ }
+
+ // If we cannot use or generate enough data from a secure source
+ // use this loop to generate a good set of pseudo random data.
+ // This works by initializing a random state using a pile of
unstable data
+ // and continually shoving it through a hash along with a
variable salt.
+ // We hash the random state with more salt to avoid the state
from leaking
+ // out and being used to predict the /randomness/ that follows.
+ if ( strlen( $buffer ) < $bytes ) {
+ wfDebug( __METHOD__ . ": Falling back to using a pseudo
random state to generate randomness.\n" );
+ }
+ while ( strlen( $buffer ) < $bytes ) {
+ wfProfileIn( __METHOD__ . '-fallback' );
+ $buffer .= $this->hmac( $this->randomState(), mt_rand()
);
+ // This code is never really cryptographically strong,
if we use it
+ // at all, then set strong to false.
+ $this->strong = false;
+ wfProfileOut( __METHOD__ . '-fallback' );
+ }
+
+ // Once the buffer has been filled up with enough random data
to fulfill
+ // the request shift off enough data to handle the request and
leave the
+ // unused portion left inside the buffer for the next request
for random data
+ $generated = substr( $buffer, 0, $bytes );
+ $buffer = substr( $buffer, $bytes );
+
+ wfDebug( __METHOD__ . ": " . strlen( $buffer ) . " bytes of
randomness leftover in the buffer.\n" );
+
+ wfProfileOut( __METHOD__ );
+ return $generated;
+ }
+
+ /**
+ * @see self::generateHex()
+ */
+ public function realGenerateHex( $chars, $forceStrong = false ) {
+ // hex strings are 2x the length of raw binary so we divide the
length in half
+ // odd numbers will result in a .5 that leads the generate()
being 1 character
+ // short, so we use ceil() to ensure that we always have enough
bytes
+ $bytes = ceil( $chars / 2 );
+ // Generate the data and then convert it to a hex string
+ $hex = bin2hex( $this->generate( $bytes, $forceStrong ) );
+ // A bit of paranoia here, the caller asked for a specific
length of string
+ // here, and it's possible (eg when given an odd number) that
we may actually
+ // have at least 1 char more than they asked for. Just in case
they made this
+ // call intending to insert it into a database that does
truncation we don't
+ // want to give them too much and end up with their database
and their live
+ // code having two different values because part of what we
gave them is truncated
+ // hence, we strip out any run of characters longer than what
we were asked for.
+ return substr( $hex, 0, $chars );
+ }
+
+ /** Publicly exposed static methods **/
+
+ /**
+ * Return a singleton instance of MWCryptRand
+ */
+ protected static function singleton() {
+ if ( is_null( self::$singleton ) ) {
+ self::$singleton = new self;
+ }
+ return self::$singleton;
+ }
+
+ /**
+ * Return a boolean indicating whether or not the source used for
cryptographic
+ * random bytes generation in the previously run generate* call
+ * was cryptographically strong.
+ *
+ * @return bool Returns true if the source was strong, false if not.
+ */
+ public static function wasStrong() {
+ return self::singleton()->realWasStrong();
+ }
+
+ /**
+ * Generate a run of (ideally) cryptographically random data and return
+ * it in raw binary form.
+ * You can use MWCryptRand::wasStrong() if you wish to know if the
source used
+ * was cryptographically strong.
+ *
+ * @param $bytes int the number of bytes of random data to generate
+ * @param $forceStrong bool Pass true if you want generate to prefer
cryptographically
+ * strong sources of entropy even if reading
from them may steal
+ * more entropy from the system than optimal.
+ * @return String Raw binary random data
+ */
+ public static function generate( $bytes, $forceStrong = false ) {
+ return self::singleton()->realGenerate( $bytes, $forceStrong );
+ }
+
+ /**
+ * Generate a run of (ideally) cryptographically random data and return
+ * it in hexadecimal string format.
+ * You can use MWCryptRand::wasStrong() if you wish to know if the
source used
+ * was cryptographically strong.
+ *
+ * @param $chars int the number of hex chars of random data to generate
+ * @param $forceStrong bool Pass true if you want generate to prefer
cryptographically
+ * strong sources of entropy even if reading
from them may steal
+ * more entropy from the system than optimal.
+ * @return String Hexadecimal random data
+ */
+ public static function generateHex( $chars, $forceStrong = false ) {
+ return self::singleton()->realGenerateHex( $chars, $forceStrong
);
+ }
+
+}
Modified: branches/wmf/1.19wmf1/includes/DefaultSettings.php
===================================================================
--- branches/wmf/1.19wmf1/includes/DefaultSettings.php 2012-03-22 19:00:08 UTC
(rev 114428)
+++ branches/wmf/1.19wmf1/includes/DefaultSettings.php 2012-03-22 19:43:00 UTC
(rev 114429)
@@ -2581,13 +2581,6 @@
);
/**
- * Whether to embed private modules inline with HTML output or to bypass
- * caching and check the user parameter against $wgUser to prevent
- * unauthorized access to private modules.
- */
-$wgResourceLoaderInlinePrivateModules = true;
-
-/**
* The default debug mode (on/off) for of ResourceLoader requests. This will
still
* be overridden when the debug URL parameter is used.
*/
Modified: branches/wmf/1.19wmf1/includes/GlobalFunctions.php
===================================================================
--- branches/wmf/1.19wmf1/includes/GlobalFunctions.php 2012-03-22 19:00:08 UTC
(rev 114428)
+++ branches/wmf/1.19wmf1/includes/GlobalFunctions.php 2012-03-22 19:43:00 UTC
(rev 114429)
@@ -3269,6 +3269,33 @@
}
/**
+ * Override session_id before session startup if php's built-in
+ * session generation code is not secure.
+ */
+function wfFixSessionID() {
+ // If the cookie or session id is already set we already have a session
and should abort
+ if ( isset( $_COOKIE[ session_name() ] ) || session_id() ) {
+ return;
+ }
+
+ // PHP's built-in session entropy is enabled if:
+ // - entropy_file is set or you're on Windows with php 5.3.3+
+ // - AND entropy_length is > 0
+ // We treat it as disabled if it doesn't have an entropy length of at
least 32
+ $entropyEnabled = (
+ ( wfIsWindows() && version_compare( PHP_VERSION,
'5.3.3', '>=' ) )
+ || ini_get( 'session.entropy_file' )
+ )
+ && intval( ini_get( 'session.entropy_length' ) ) >= 32;
+
+ // If built-in entropy is not enabled or not sufficient override php's
built in session id generation code
+ if ( !$entropyEnabled ) {
+ wfDebug( __METHOD__ . ": PHP's built in entropy is disabled or
not sufficient, overriding session id generation using our cryptrand source.\n"
);
+ session_id( MWCryptRand::generateHex( 32 ) );
+ }
+}
+
+/**
* Initialise php session
*
* @param $sessionId Bool
@@ -3307,6 +3334,8 @@
session_cache_limiter( 'private, must-revalidate' );
if ( $sessionId ) {
session_id( $sessionId );
+ } else {
+ wfFixSessionID();
}
wfSuppressWarnings();
session_start();
Property changes on: branches/wmf/1.19wmf1/includes/GlobalFunctions.php
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/FileBackend/phase3/includes/GlobalFunctions.php:99972-106750
/branches/JSTesting/includes/GlobalFunctions.php:100352-107913
/branches/REL1_15/phase3/includes/GlobalFunctions.php:51646
/branches/new-installer/phase3/includes/GlobalFunctions.php:43664-66004
/branches/resourceloader/phase3/includes/GlobalFunctions.php:71750
/branches/sqlite/includes/GlobalFunctions.php:58211-58321
/branches/wmf/1.17wmf1/includes/GlobalFunctions.php:81718
/branches/wmf-deployment/includes/GlobalFunctions.php:53381
+ /branches/FileBackend/phase3/includes/GlobalFunctions.php:99972-106750
/branches/JSTesting/includes/GlobalFunctions.php:100352-107913
/branches/REL1_15/phase3/includes/GlobalFunctions.php:51646
/branches/REL1_19/phase3/includes/GlobalFunctions.php:114241,114283,114355
/branches/new-installer/phase3/includes/GlobalFunctions.php:43664-66004
/branches/resourceloader/phase3/includes/GlobalFunctions.php:71750
/branches/sqlite/includes/GlobalFunctions.php:58211-58321
/branches/wmf/1.17wmf1/includes/GlobalFunctions.php:81718
/branches/wmf-deployment/includes/GlobalFunctions.php:53381
/trunk/phase3/includes/GlobalFunctions.php:114354
Modified: branches/wmf/1.19wmf1/includes/OutputPage.php
===================================================================
--- branches/wmf/1.19wmf1/includes/OutputPage.php 2012-03-22 19:00:08 UTC
(rev 114428)
+++ branches/wmf/1.19wmf1/includes/OutputPage.php 2012-03-22 19:43:00 UTC
(rev 114429)
@@ -2505,7 +2505,7 @@
* @return string html <script> and <style> tags
*/
protected function makeResourceLoaderLink( $modules, $only, $useESI =
false, array $extraQuery = array(), $loadCall = false ) {
- global $wgResourceLoaderUseESI,
$wgResourceLoaderInlinePrivateModules;
+ global $wgResourceLoaderUseESI;
if ( !count( $modules ) ) {
return '';
@@ -2584,10 +2584,11 @@
continue;
}
- // Support inlining of private modules if configured as
such. Note that these
- // modules should be loaded from getHeadScripts()
before the first loader call.
- // Otherwise other modules can't properly use them as
dependencies (bug 30914)
- if ( $group === 'private' &&
$wgResourceLoaderInlinePrivateModules ) {
+ // Inline private modules. These can't be loaded
through load.php for security
+ // reasons, see bug 34907. Note that these modules
should be loaded from
+ // getHeadScripts() before the first loader call.
Otherwise other modules can't
+ // properly use them as dependencies (bug 30914)
+ if ( $group === 'private' ) {
if ( $only == ResourceLoaderModule::TYPE_STYLES
) {
$links .= Html::inlineStyle(
$resourceLoader->makeModuleResponse( $context, $modules )
Modified: branches/wmf/1.19wmf1/includes/User.php
===================================================================
--- branches/wmf/1.19wmf1/includes/User.php 2012-03-22 19:00:08 UTC (rev
114428)
+++ branches/wmf/1.19wmf1/includes/User.php 2012-03-22 19:43:00 UTC (rev
114429)
@@ -831,23 +831,20 @@
}
/**
- * Return a random password. Sourced from mt_rand, so it's not
particularly secure.
- * @todo hash random numbers to improve security, like generateToken()
+ * Return a random password.
*
* @return String new random password
*/
public static function randomPassword() {
global $wgMinimalPasswordLength;
- $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
- $l = strlen( $pwchars ) - 1;
-
- $pwlength = max( 7, $wgMinimalPasswordLength );
- $digit = mt_rand( 0, $pwlength - 1 );
- $np = '';
- for ( $i = 0; $i < $pwlength; $i++ ) {
- $np .= $i == $digit ? chr( mt_rand( 48, 57 ) ) :
$pwchars[ mt_rand( 0, $l ) ];
- }
- return $np;
+ // Decide the final password length based on our min password
length, stopping at a minimum of 10 chars
+ $length = max( 10, $wgMinimalPasswordLength );
+ // Multiply by 1.25 to get the number of hex characters we need
+ $length = $length * 1.25;
+ // Generate random hex chars
+ $hex = MWCryptRand::generateHex( $length );
+ // Convert from base 16 to base 32 to get a proper password
like string
+ return wfBaseConvert( $hex, 16, 32 );
}
/**
@@ -877,7 +874,7 @@
$this->mTouched = '0'; # Allow any pages to be cached
}
- $this->setToken(); # Random
+ $this->mToken = null; // Don't run cryptographic functions till
we need a token
$this->mEmailAuthenticated = null;
$this->mEmailToken = '';
$this->mEmailTokenExpires = null;
@@ -984,11 +981,11 @@
return false;
}
- if ( $request->getSessionData( 'wsToken' ) !== null ) {
- $passwordCorrect = $proposedUser->getToken() ===
$request->getSessionData( 'wsToken' );
+ if ( $request->getSessionData( 'wsToken' ) ) {
+ $passwordCorrect = $proposedUser->getToken( false ) ===
$request->getSessionData( 'wsToken' );
$from = 'session';
- } elseif ( $request->getCookie( 'Token' ) !== null ) {
- $passwordCorrect = $proposedUser->getToken() ===
$request->getCookie( 'Token' );
+ } elseif ( $request->getCookie( 'Token' ) ) {
+ $passwordCorrect = $proposedUser->getToken( false ) ===
$request->getCookie( 'Token' );
$from = 'cookie';
} else {
# No session or persistent login cookie
@@ -1093,6 +1090,9 @@
}
$this->mTouched = wfTimestamp( TS_MW,
$row->user_touched );
$this->mToken = $row->user_token;
+ if ( $this->mToken == '' ) {
+ $this->mToken = null;
+ }
$this->mEmailAuthenticated = wfTimestampOrNull( TS_MW,
$row->user_email_authenticated );
$this->mEmailToken = $row->user_email_token;
$this->mEmailTokenExpires = wfTimestampOrNull( TS_MW,
$row->user_email_token_expires );
@@ -2015,10 +2015,14 @@
/**
* Get the user's current token.
+ * @param $forceCreation Force the generation of a new token if the
user doesn't have one (default=true for backwards compatibility)
* @return String Token
*/
- public function getToken() {
+ public function getToken( $forceCreation = true ) {
$this->load();
+ if ( !$this->mToken && $forceCreation ) {
+ $this->setToken();
+ }
return $this->mToken;
}
@@ -2032,14 +2036,7 @@
global $wgSecretKey, $wgProxyKey;
$this->load();
if ( !$token ) {
- if ( $wgSecretKey ) {
- $key = $wgSecretKey;
- } elseif ( $wgProxyKey ) {
- $key = $wgProxyKey;
- } else {
- $key = microtime();
- }
- $this->mToken = md5( $key . mt_rand( 0, 0x7fffffff ) .
wfWikiID() . $this->mId );
+ $this->mToken = MWCryptRand::generateHex(
USER_TOKEN_LENGTH );
} else {
$this->mToken = $token;
}
@@ -2745,6 +2742,14 @@
$this->load();
if ( 0 == $this->mId ) return;
+ if ( !$this->mToken ) {
+ // When token is empty or NULL generate a new one and
then save it to the database
+ // This allows a wiki to re-secure itself after a leak
of it's user table or $wgSecretKey
+ // Simply by setting every cell in the user_token
column to NULL and letting them be
+ // regenerated as users log back into the wiki.
+ $this->setToken();
+ $this->saveSettings();
+ }
$session = array(
'wsUserID' => $this->mId,
'wsToken' => $this->mToken,
@@ -2821,7 +2826,7 @@
'user_email' => $this->mEmail,
'user_email_authenticated' =>
$dbw->timestampOrNull( $this->mEmailAuthenticated ),
'user_touched' => $dbw->timestamp(
$this->mTouched ),
- 'user_token' => $this->mToken,
+ 'user_token' => strval( $this->mToken ),
'user_email_token' => $this->mEmailToken,
'user_email_token_expires' =>
$dbw->timestampOrNull( $this->mEmailTokenExpires ),
), array( /* WHERE */
@@ -2887,7 +2892,7 @@
'user_email' => $user->mEmail,
'user_email_authenticated' => $dbw->timestampOrNull(
$user->mEmailAuthenticated ),
'user_real_name' => $user->mRealName,
- 'user_token' => $user->mToken,
+ 'user_token' => strval( $user->mToken ),
'user_registration' => $dbw->timestamp(
$user->mRegistration ),
'user_editcount' => 0,
);
@@ -2920,7 +2925,7 @@
'user_email' => $this->mEmail,
'user_email_authenticated' =>
$dbw->timestampOrNull( $this->mEmailAuthenticated ),
'user_real_name' => $this->mRealName,
- 'user_token' => $this->mToken,
+ 'user_token' => strval( $this->mToken ),
'user_registration' => $dbw->timestamp(
$this->mRegistration ),
'user_editcount' => 0,
), __METHOD__
@@ -3184,7 +3189,7 @@
} else {
$token = $request->getSessionData( 'wsEditToken' );
if ( $token === null ) {
- $token = self::generateToken();
+ $token = MWCryptRand::generateHex( 32 );
$request->setSessionData( 'wsEditToken', $token
);
}
if( is_array( $salt ) ) {
@@ -3201,8 +3206,7 @@
* @return String The new random token
*/
public static function generateToken( $salt = '' ) {
- $token = dechex( mt_rand() ) . dechex( mt_rand() );
- return md5( $token . $salt );
+ return MWCryptRand::generateHex( 32 );
}
/**
@@ -3308,12 +3312,11 @@
global $wgUserEmailConfirmationTokenExpiry;
$now = time();
$expires = $now + $wgUserEmailConfirmationTokenExpiry;
- $expiration = wfTimestamp( TS_MW, $expires );
- $token = self::generateToken( $this->mId . $this->mEmail .
$expires );
+ $this->load();
+ $token = MWCryptRand::generateHex( 32 );
$hash = md5( $token );
- $this->load();
$this->mEmailToken = $hash;
- $this->mEmailTokenExpires = $expiration;
+ $this->mEmailTokenExpires = wfTimestamp( TS_MW, $expires );
return $token;
}
@@ -3862,7 +3865,7 @@
if( $wgPasswordSalt ) {
if ( $salt === false ) {
- $salt = substr( wfGenerateToken(), 0, 8 );
+ $salt = MWCryptRand::generateHex( 8 );
}
return ':B:' . $salt . ':' . md5( $salt . '-' . md5(
$password ) );
} else {
Property changes on: branches/wmf/1.19wmf1/includes/User.php
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JSTesting/includes/User.php:100352-107913
/branches/REL1_15/phase3/includes/User.php:51646
/branches/new-installer/phase3/includes/User.php:43664-66004
/branches/sqlite/includes/User.php:58211-58321
/branches/wmf/1.18wmf1/includes/User.php:97508,111667
/branches/wmf-deployment/includes/User.php:53381
/trunk/phase3/includes/User.php:111029,111034,111067,111085,111128,111144,111251,111397,111427,111571,111574,111597,111658,111673,111695,111697,111750,111827,111965-111967,112021,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112128,112132-112133,112152,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112534,112563,112700,112839-112840,112843,112855,112866,112951,112995,113099,113169,113195,113312,113412,113441,114234
+ /branches/JSTesting/includes/User.php:100352-107913
/branches/REL1_15/phase3/includes/User.php:51646
/branches/REL1_19/phase3/includes/User.php:114241,114283,114355
/branches/new-installer/phase3/includes/User.php:43664-66004
/branches/sqlite/includes/User.php:58211-58321
/branches/wmf/1.18wmf1/includes/User.php:97508,111667
/branches/wmf-deployment/includes/User.php:53381
/trunk/phase3/includes/User.php:111029,111034,111067,111085,111128,111144,111251,111397,111427,111571,111574,111597,111658,111673,111695,111697,111750,111827,111965-111967,112021,112045-112046,112049,112061-112063,112065-112066,112070-112071,112079,112128,112132-112133,112152,112184,112259,112290,112347,112374,112378,112381,112383,112397,112408,112474,112526,112534,112563,112700,112839-112840,112843,112855,112866,112951,112995,113099,113169,113195,113312,113412,113441,114234
Modified: branches/wmf/1.19wmf1/includes/api/ApiMain.php
===================================================================
--- branches/wmf/1.19wmf1/includes/api/ApiMain.php 2012-03-22 19:00:08 UTC
(rev 114428)
+++ branches/wmf/1.19wmf1/includes/api/ApiMain.php 2012-03-22 19:43:00 UTC
(rev 114429)
@@ -595,7 +595,7 @@
// Die if token required, but not provided (unless there is a
gettoken parameter)
$salt = $module->getTokenSalt();
- if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) {
+ if ( $salt !== false && !$moduleParams['gettoken'] ) {
if ( !isset( $moduleParams['token'] ) ) {
$this->dieUsageMsg( array( 'missingparam',
'token' ) );
} else {
Modified: branches/wmf/1.19wmf1/includes/installer/Installer.php
===================================================================
--- branches/wmf/1.19wmf1/includes/installer/Installer.php 2012-03-22
19:00:08 UTC (rev 114428)
+++ branches/wmf/1.19wmf1/includes/installer/Installer.php 2012-03-22
19:43:00 UTC (rev 114429)
@@ -1405,8 +1405,7 @@
}
/**
- * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead
of
- * /dev/urandom
+ * Generate $wgSecretKey. Will warn if we had to use an insecure random
source.
*
* @return Status
*/
@@ -1419,8 +1418,8 @@
}
/**
- * Generate a secret value for variables using either
- * /dev/urandom or mt_rand(). Produce a warning in the later case.
+ * Generate a secret value for variables using our CryptRand generator.
+ * Produce a warning if the random source was insecure.
*
* @param $keys Array
* @return Status
@@ -1428,28 +1427,18 @@
protected function doGenerateKeys( $keys ) {
$status = Status::newGood();
- wfSuppressWarnings();
- $file = fopen( "/dev/urandom", "r" );
- wfRestoreWarnings();
-
+ $strong = true;
foreach ( $keys as $name => $length ) {
- if ( $file ) {
- $secretKey = bin2hex( fread( $file,
$length / 2 ) );
- } else {
- $secretKey = '';
-
- for ( $i = 0; $i < $length / 8; $i++ ) {
- $secretKey .= dechex( mt_rand( 0,
0x7fffffff ) );
- }
+ $secretKey = MWCryptRand::generateHex( $length, true );
+ if ( !MWCryptRand::wasStrong() ) {
+ $strong = false;
}
$this->setVar( $name, $secretKey );
}
- if ( $file ) {
- fclose( $file );
- } else {
- $names = array_keys ( $keys );
+ if ( !$strong ) {
+ $names = array_keys( $keys );
$names = preg_replace( '/^(.*)$/', '\$$1', $names );
global $wgLang;
$status->warning( 'config-insecure-keys',
$wgLang->listToText( $names ), count( $names ) );
Modified: branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoader.php
===================================================================
--- branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoader.php
2012-03-22 19:00:08 UTC (rev 114428)
+++ branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoader.php
2012-03-22 19:43:00 UTC (rev 114429)
@@ -173,7 +173,7 @@
$cache->set( $key, $result );
} catch ( Exception $exception ) {
// Return exception as a comment
- $result = "/*\n{$exception->__toString()}\n*/\n";
+ $result = $this->makeComment( $exception->__toString()
);
}
wfProfileOut( __METHOD__ );
@@ -430,13 +430,20 @@
ob_start();
wfProfileIn( __METHOD__ );
- $exceptions = '';
+ $errors = '';
// Split requested modules into two groups, modules and missing
$modules = array();
$missing = array();
foreach ( $context->getModules() as $name ) {
if ( isset( $this->moduleInfos[$name] ) ) {
+ $module = $this->getModule( $name );
+ // Do not allow private modules to be loaded
from the web.
+ // This is a security issue, see bug 34907.
+ if ( $module->getGroup() === 'private' ) {
+ $errors .= $this->makeComment( "Cannot
show private module \"$name\"" );
+ continue;
+ }
$modules[$name] = $this->getModule( $name );
} else {
$missing[] = $name;
@@ -448,12 +455,11 @@
$this->preloadModuleInfo( array_keys( $modules ),
$context );
} catch( Exception $e ) {
// Add exception to the output as a comment
- $exceptions .= "/*\n{$e->__toString()}\n*/\n";
+ $errors .= $this->makeComment( $e->__toString() );
}
wfProfileIn( __METHOD__.'-getModifiedTime' );
- $private = false;
// To send Last-Modified and support If-Modified-Since, we need
to detect
// the last modified time
$mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
@@ -462,22 +468,18 @@
* @var $module ResourceLoaderModule
*/
try {
- // Bypass Squid and other shared caches if the
request includes any private modules
- if ( $module->getGroup() === 'private' ) {
- $private = true;
- }
// Calculate maximum modified time
$mtime = max( $mtime, $module->getModifiedTime(
$context ) );
} catch ( Exception $e ) {
// Add exception to the output as a comment
- $exceptions .= "/*\n{$e->__toString()}\n*/\n";
+ $errors .= $this->makeComment( $e->__toString()
);
}
}
wfProfileOut( __METHOD__.'-getModifiedTime' );
// Send content type and cache related headers
- $this->sendResponseHeaders( $context, $mtime, $private );
+ $this->sendResponseHeaders( $context, $mtime );
// If there's an If-Modified-Since header, respond with a 304
appropriately
if ( $this->tryRespondLastModified( $context, $mtime ) ) {
@@ -489,20 +491,20 @@
$response = $this->makeModuleResponse( $context, $modules,
$missing );
// Prepend comments indicating exceptions
- $response = $exceptions . $response;
+ $response = $errors . $response;
// Capture any PHP warnings from the output buffer and append
them to the
// response in a comment if we're in debug mode.
if ( $context->getDebug() && strlen( $warnings =
ob_get_contents() ) ) {
- $response = "/*\n$warnings\n*/\n" . $response;
+ $response = $this->makeComment( $warnings ) . $response;
}
// Remove the output buffer and output the response
ob_end_clean();
echo $response;
- // Save response to file cache unless there are private modules
or errors
- if ( isset( $fileCache ) && !$private && !$exceptions &&
!$missing ) {
+ // Save response to file cache unless there are errors
+ if ( isset( $fileCache ) && !$errors && !$missing ) {
// Cache single modules...and other requests if there
are enough hits
if ( ResourceFileCache::useFileCache( $context ) ) {
if ( $fileCache->isCacheWorthy() ) {
@@ -520,10 +522,9 @@
* Send content type and last modified headers to the client.
* @param $context ResourceLoaderContext
* @param $mtime string TS_MW timestamp to use for last-modified
- * @param $private bool True iff response contains any private modules
* @return void
*/
- protected function sendResponseHeaders( ResourceLoaderContext $context,
$mtime, $private ) {
+ protected function sendResponseHeaders( ResourceLoaderContext $context,
$mtime ) {
global $wgResourceLoaderMaxage;
// If a version wasn't specified we need a shorter expiry time
for updates
// to propagate to clients quickly
@@ -547,13 +548,8 @@
header( 'Cache-Control: private, no-cache,
must-revalidate' );
header( 'Pragma: no-cache' );
} else {
- if ( $private ) {
- header( "Cache-Control: private,
max-age=$maxage" );
- $exp = $maxage;
- } else {
- header( "Cache-Control: public,
max-age=$maxage, s-maxage=$smaxage" );
- $exp = min( $maxage, $smaxage );
- }
+ header( "Cache-Control: public, max-age=$maxage,
s-maxage=$smaxage" );
+ $exp = min( $maxage, $smaxage );
header( 'Expires: ' . wfTimestamp( TS_RFC2822, $exp +
time() ) );
}
}
@@ -650,6 +646,11 @@
return false; // cache miss
}
+ protected function makeComment( $text ) {
+ $encText = str_replace( '*/', '* /', $text );
+ return "/*\n$encText\n*/\n";
+ }
+
/**
* Generates code for a response
*
@@ -674,7 +675,7 @@
$blobs = MessageBlobStore::get( $this,
$modules, $context->getLanguage() );
} catch ( Exception $e ) {
// Add exception to the output as a comment
- $exceptions .= "/*\n{$e->__toString()}\n*/\n";
+ $exceptions .= $this->makeComment(
$e->__toString() );
}
} else {
$blobs = array();
@@ -753,7 +754,7 @@
}
} catch ( Exception $e ) {
// Add exception to the output as a comment
- $exceptions .= "/*\n{$e->__toString()}\n*/\n";
+ $exceptions .= $this->makeComment(
$e->__toString() );
// Register module as missing
$missing[] = $name;
Modified:
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
===================================================================
---
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
2012-03-22 19:00:08 UTC (rev 114428)
+++
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
2012-03-22 19:43:00 UTC (rev 114429)
@@ -44,41 +44,18 @@
}
global $wgUser;
-
- if ( $context->getUser() === $wgUser->getName() ) {
- return $this->modifiedTime[$hash] = wfTimestamp(
TS_UNIX, $wgUser->getTouched() );
- } else {
- return 1;
- }
+ return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX,
$wgUser->getTouched() );
}
-
- /**
- * Fetch the context's user options, or if it doesn't match current
user,
- * the default options.
- *
- * @param $context ResourceLoaderContext: Context object
- * @return Array: List of user options keyed by option name
- */
- protected function contextUserOptions( ResourceLoaderContext $context )
{
- global $wgUser;
-
- // Verify identity -- this is a private module
- if ( $context->getUser() === $wgUser->getName() ) {
- return $wgUser->getOptions();
- } else {
- return User::getDefaultOptions();
- }
- }
/**
* @param $context ResourceLoaderContext
* @return array
*/
public function getStyles( ResourceLoaderContext $context ) {
- global $wgAllowUserCssPrefs;
+ global $wgAllowUserCssPrefs, $wgUser;
if ( $wgAllowUserCssPrefs ) {
- $options = $this->contextUserOptions( $context );
+ $options = $wgUser->getOptions();
// Build CSS rules
$rules = array();
Modified:
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserOptionsModule.php
===================================================================
---
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserOptionsModule.php
2012-03-22 19:00:08 UTC (rev 114428)
+++
branches/wmf/1.19wmf1/includes/resourceloader/ResourceLoaderUserOptionsModule.php
2012-03-22 19:43:00 UTC (rev 114429)
@@ -42,41 +42,19 @@
if ( isset( $this->modifiedTime[$hash] ) ) {
return $this->modifiedTime[$hash];
}
-
+
global $wgUser;
-
- if ( $context->getUser() === $wgUser->getName() ) {
- return $this->modifiedTime[$hash] = wfTimestamp(
TS_UNIX, $wgUser->getTouched() );
- } else {
- return 1;
- }
+ return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX,
$wgUser->getTouched() );
}
/**
- * Fetch the context's user options, or if it doesn't match current
user,
- * the default options.
- *
- * @param $context ResourceLoaderContext: Context object
- * @return Array: List of user options keyed by option name
- */
- protected function contextUserOptions( ResourceLoaderContext $context )
{
- global $wgUser;
-
- // Verify identity -- this is a private module
- if ( $context->getUser() === $wgUser->getName() ) {
- return $wgUser->getOptions();
- } else {
- return User::getDefaultOptions();
- }
- }
-
- /**
* @param $context ResourceLoaderContext
* @return string
*/
public function getScript( ResourceLoaderContext $context ) {
+ global $wgUser;
return Xml::encodeJsCall( 'mw.user.options.set',
- array( $this->contextUserOptions( $context ) ) );
+ array( $wgUser->getOptions() ) );
}
/**
Property changes on: branches/wmf/1.19wmf1/includes/specials
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JSTesting/includes/specials:100352-107913
/branches/REL1_15/phase3/includes/specials:51646
/branches/sqlite/includes/specials:58211-58321
/branches/wmf-deployment/includes/specials:53381,56967
/trunk/phase3/includes/specials:111085,111128,111144,111251,111750,112397,112408,112474,112843,112918,112995,113099,113169,113214,113394,113415,113617,113710,113727,113737,113816,113892
+ /branches/JSTesting/includes/specials:100352-107913
/branches/REL1_15/phase3/includes/specials:51646
/branches/REL1_19/phase3/includes/specials:114241,114283,114355
/branches/sqlite/includes/specials:58211-58321
/branches/wmf-deployment/includes/specials:53381,56967
/trunk/phase3/includes/specials:111085,111128,111144,111251,111750,112397,112408,112474,112843,112918,112995,113099,113169,113214,113394,113415,113617,113710,113727,113737,113816,113892
Modified: branches/wmf/1.19wmf1/includes/specials/SpecialUpload.php
===================================================================
--- branches/wmf/1.19wmf1/includes/specials/SpecialUpload.php 2012-03-22
19:00:08 UTC (rev 114428)
+++ branches/wmf/1.19wmf1/includes/specials/SpecialUpload.php 2012-03-22
19:43:00 UTC (rev 114429)
@@ -111,14 +111,7 @@
// If it was posted check for the token (no remote POST'ing
with user credentials)
$token = $request->getVal( 'wpEditToken' );
- if( $this->mSourceType == 'file' && $token == null ) {
- // Skip token check for file uploads as that can't be
faked via JS...
- // Some client-side tools don't expect to need to send
wpEditToken
- // with their submissions, as that's new in 1.16.
- $this->mTokenOk = true;
- } else {
- $this->mTokenOk = $this->getUser()->matchEditToken(
$token );
- }
+ $this->mTokenOk = $this->getUser()->matchEditToken( $token );
$this->uploadFormTextTop = '';
$this->uploadFormTextAfterSummary = '';
Modified: branches/wmf/1.19wmf1/includes/specials/SpecialUserlogin.php
===================================================================
--- branches/wmf/1.19wmf1/includes/specials/SpecialUserlogin.php
2012-03-22 19:00:08 UTC (rev 114428)
+++ branches/wmf/1.19wmf1/includes/specials/SpecialUserlogin.php
2012-03-22 19:43:00 UTC (rev 114429)
@@ -1136,9 +1136,9 @@
*/
public static function setLoginToken() {
global $wgRequest;
- // Use User::generateToken() instead of $user->editToken()
+ // Generate a token directly instead of using $user->editToken()
// because the latter reuses $_SESSION['wsEditToken']
- $wgRequest->setSessionData( 'wsLoginToken',
User::generateToken() );
+ $wgRequest->setSessionData( 'wsLoginToken',
MWCryptRand::generateHex( 32 ) );
}
/**
@@ -1162,7 +1162,7 @@
*/
public static function setCreateaccountToken() {
global $wgRequest;
- $wgRequest->setSessionData( 'wsCreateaccountToken',
User::generateToken() );
+ $wgRequest->setSessionData( 'wsCreateaccountToken',
MWCryptRand::generateHex( 32 ) );
}
/**
Modified: branches/wmf/1.19wmf1/includes/specials/SpecialWatchlist.php
===================================================================
--- branches/wmf/1.19wmf1/includes/specials/SpecialWatchlist.php
2012-03-22 19:00:08 UTC (rev 114428)
+++ branches/wmf/1.19wmf1/includes/specials/SpecialWatchlist.php
2012-03-22 19:43:00 UTC (rev 114429)
@@ -43,7 +43,7 @@
// Add feed links
$wlToken = $user->getOption( 'watchlisttoken' );
if ( !$wlToken ) {
- $wlToken = sha1( mt_rand() . microtime( true ) );
+ $wlToken = MWCryptRand::generateHex( 40 );
$user->setOption( 'watchlisttoken', $wlToken );
$user->saveSettings();
}
Property changes on:
branches/wmf/1.19wmf1/includes/specials/SpecialWatchlist.php
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JSTesting/includes/specials/SpecialWatchlist.php:100352-107913
/branches/REL1_15/phase3/includes/specials/SpecialWatchlist.php:51646
/branches/sqlite/includes/specials/SpecialWatchlist.php:58211-58321
/branches/wmf-deployment/includes/specials/SpecialWatchlist.php:53381,56967
/trunk/phase3/includes/specials/SpecialWatchlist.php:111085,111128,111144,111251,111750,111882,112397,112408,112474
+ /branches/JSTesting/includes/specials/SpecialWatchlist.php:100352-107913
/branches/REL1_15/phase3/includes/specials/SpecialWatchlist.php:51646
/branches/REL1_19/phase3/includes/specials/SpecialWatchlist.php:114241,114283,114355
/branches/sqlite/includes/specials/SpecialWatchlist.php:58211-58321
/branches/wmf-deployment/includes/specials/SpecialWatchlist.php:53381,56967
/trunk/phase3/includes/specials/SpecialWatchlist.php:111085,111128,111144,111251,111750,111882,112397,112408,112474
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs