eval() is evil! Improper escaping allowed, at a minimum, arbitrary global
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 30 Aug 2005 23:06:40 +0000 (23:06 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 30 Aug 2005 23:06:40 +0000 (23:06 +0000)
variable interpolations into Special:Upload output on malicious data
in MediaWiki:Licenses.

RELEASE-NOTES
includes/Licenses.php

index 4e70c21..6224efc 100644 (file)
@@ -74,6 +74,7 @@ fully support the editing toolbar, but was found to be too confusing.
 * Support for a license selection box on Special:Upload, configurable from MediaWiki:Licenses
 * Security fix for <math>
 * Security fix for tables
+* Security fix for Special:Upload license selection list
 
 
 === Caveats ===
index 1d78c31..316aacd 100644 (file)
@@ -60,8 +60,7 @@ class Licenses {
                                
                                if ( strpos( $line, '|' ) !== false ) {
                                        $obj = new License( $line );
-                                       // TODO: Do this without using eval()
-                                       eval( '$this->licenses' . $this->makeIndexes( $levels ) . '[] = $obj;' );
+                                       $this->stackItem( $this->licenses, $levels, $obj );
                                } else {
                                        if ( $level < count( $levels ) )
                                                $levels = array_slice( $levels, count( $levels ) - $level );
@@ -84,15 +83,14 @@ class Licenses {
                return array( $count, ltrim( $str, '* ' ) );
        }
        
-       function makeIndexes( $arr ) {
-               $str = '';
-       
-               wfSuppressWarnings();
-               foreach ( $arr as $item )
-                       $str .= '["' . addslashes( $item ) . '"]';
-               
-               wfRestoreWarnings();
-               return $str;
+       function stackItem( &$list, $path, $item ) {
+               $position =& $list;
+               if( $path ) {
+                       foreach( $path as $key ) {
+                               $position =& $position[$key];
+                       }
+               }
+               $position[] = $item;
        }
 
        function makeHtml( &$tagset, $depth = 0 ) {