diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2008-12-15 18:02:47 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2008-12-15 18:02:47 +0100 |
commit | 396b28f3d881f5debd888ba9bb9b47c2d478a76f (patch) | |
tree | 10d6e1a721ee4ef69def34a57f02d7eb3fc9e31e /includes/StreamFile.php | |
parent | 0be4d3ccf6c4fe98a72704f9463ecdea2ee5e615 (diff) |
update to Mediawiki 1.13.3; some cleanups
Diffstat (limited to 'includes/StreamFile.php')
-rw-r--r-- | includes/StreamFile.php | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/includes/StreamFile.php b/includes/StreamFile.php index b4bf531c..4abd7364 100644 --- a/includes/StreamFile.php +++ b/includes/StreamFile.php @@ -31,6 +31,12 @@ function wfStreamFile( $fname, $headers = array() ) { header('Content-type: application/x-wiki'); } + // Don't stream it out as text/html if there was a PHP error + if ( headers_sent() ) { + echo "Headers already sent, terminating.\n"; + return; + } + global $wgContLanguageCode; header( "Content-Disposition: inline;filename*=utf-8'$wgContLanguageCode'" . urlencode( basename( $fname ) ) ); @@ -53,25 +59,51 @@ function wfStreamFile( $fname, $headers = array() ) { } /** */ -function wfGetType( $filename ) { +function wfGetType( $filename, $safe = true ) { global $wgTrivialMimeDetection; + $ext = strrchr($filename, '.'); + $ext = $ext === false ? '' : strtolower( substr( $ext, 1 ) ); + # trivial detection by file extension, # used for thumbnails (thumb.php) if ($wgTrivialMimeDetection) { - $ext= strtolower(strrchr($filename, '.')); - switch ($ext) { - case '.gif': return 'image/gif'; - case '.png': return 'image/png'; - case '.jpg': return 'image/jpeg'; - case '.jpeg': return 'image/jpeg'; + case 'gif': return 'image/gif'; + case 'png': return 'image/png'; + case 'jpg': return 'image/jpeg'; + case 'jpeg': return 'image/jpeg'; } return 'unknown/unknown'; } - else { - $magic = MimeMagic::singleton(); - return $magic->guessMimeType($filename); //full fancy mime detection + + $magic = MimeMagic::singleton(); + // Use the extension only, rather than magic numbers, to avoid opening + // up vulnerabilities due to uploads of files with allowed extensions + // but disallowed types. + $type = $magic->guessTypesForExtension( $ext ); + + /** + * Double-check some security settings that were done on upload but might + * have changed since. + */ + if ( $safe ) { + global $wgFileBlacklist, $wgCheckFileExtensions, $wgStrictFileExtensions, + $wgFileExtensions, $wgVerifyMimeType, $wgMimeTypeBlacklist, $wgRequest; + $form = new UploadForm( $wgRequest ); + list( $partName, $extList ) = $form->splitExtensions( $filename ); + if ( $form->checkFileExtensionList( $extList, $wgFileBlacklist ) ) { + return 'unknown/unknown'; + } + if ( $wgCheckFileExtensions && $wgStrictFileExtensions + && !$form->checkFileExtensionList( $extList, $wgFileExtensions ) ) + { + return 'unknown/unknown'; + } + if ( $wgVerifyMimeType && in_array( strtolower( $type ), $wgMimeTypeBlacklist ) ) { + return 'unknown/unknown'; + } } + return $type; } |