]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - img_auth.php
MediaWiki 1.17.1
[autoinstallsdev/mediawiki.git] / img_auth.php
index 534d1fd2ec01fbc60b3d657f9c3efb595ef86a02..4fa301b60833f81552c0d551527960cf86f9f7c2 100644 (file)
@@ -37,19 +37,29 @@ if ( $wgImgAuthPublicTest
        wfForbidden('img-auth-accessdenied','img-auth-public');
 }
 
+// Extract path and image information
+if( !isset( $_SERVER['PATH_INFO'] ) ) {
+       $path = $wgRequest->getText( 'path' );
+       if( !$path ) {
+        wfForbidden( 'img-auth-accessdenied', 'img-auth-nopathinfo' );
+       }
+       $path = "/$path";
+} else {
+       $path = $_SERVER['PATH_INFO'];
+}
+
 // Check for bug 28235: QUERY_STRING overriding the correct extension
-if ( isset( $_SERVER['QUERY_STRING'] )
-       && preg_match( '/\.[a-z]{1,4}$/i', $_SERVER['QUERY_STRING'] ) )
+$dotPos = strrpos( $path, '.' );
+$whitelist = array();
+if ( $dotPos !== false ) {
+       $whitelist[] = substr( $path, $dotPos + 1 );
+}
+if ( !$wgRequest->checkUrlExtension( $whitelist ) )
 {
-       wfForbidden( 'img-auth-accessdenied', 'img-auth-bad-query-string' );
+       return;
 }
 
-// Extract path and image information
-if( !isset( $_SERVER['PATH_INFO'] ) )
-       wfForbidden('img-auth-accessdenied','img-auth-nopathinfo');
-
-$path = $_SERVER['PATH_INFO'];
-$filename = realpath( $wgUploadDirectory . $_SERVER['PATH_INFO'] );
+$filename = realpath( $wgUploadDirectory . $path );
 $realUpload = realpath( $wgUploadDirectory );
 
 // Basic directory traversal check