Skip to content

Commit 622df8f

Browse files
author
Brion Vibber
committed
More file validity checks due to IE stupidity
1 parent 97099d0 commit 622df8f

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

RELEASE-NOTES

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,24 @@
33
Security reminder: MediaWiki does not require PHP's register_globals
44
setting since version 1.2.0. If you have it on, turn it *off* if you can.
55

6-
== Version 1.3.4, 2004-??-?? ==
6+
== Version 1.3.4, 2004-09-28 ==
7+
8+
************************** SECURITY NOTE! ******************************
9+
10+
As of 1.3.4, MediaWiki performs some screening of newly uploaded files for
11+
validity. (Some) corrupt image files, and HTML files mistakenly or
12+
maliciously masquerading as images, should now be rejected.
13+
14+
These checks protect against Internet Explorer security holes relating
15+
to type autodetection which are a potential cross-site scripting attack
16+
vector, and also rejects at least one known version of the "JPEG virus"
17+
which might attack unpatched clients.
18+
19+
If you already have invalid files uploaded this will not protect against
20+
them. If you have expanded the filetype whitelist or disabled the strict
21+
type checking, other dangerous file types may still get through. You should
22+
always be careful when allowing uploads!
23+
724

825
Changes from 1.3.3:
926
* Fixed lots of template-related bugs, esp. for cases where template

includes/SpecialUpload.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,21 @@ function mainUploadForm( $msg )
349349
</td></tr></table></form>\n" );
350350
}
351351

352+
/**
353+
* Returns false if the file is of a known type but can't be recognized,
354+
* indicating a corrupt file.
355+
* Returns true otherwise; unknown file types are not checked if given
356+
* with an unrecognized extension.
357+
*
358+
* @param string $tmpfile Pathname to the temporary upload file
359+
* @param string $extension The filename extension that the file is to be served with
360+
* @return bool
361+
*/
352362
function verify( $tmpfile, $extension ) {
363+
if( $this->triggersIEbug( $tmpfile ) ) {
364+
return false;
365+
}
366+
353367
$fname = 'SpecialUpload::verify';
354368
$mergeExtensions = array(
355369
'jpg' => 'jpeg',
@@ -418,5 +432,30 @@ function verify( $tmpfile, $extension ) {
418432
wfDebug( "$fname: all clear; passing.\n" );
419433
return true;
420434
}
435+
436+
/**
437+
* Internet Explorer for Windows performs some really stupid file type
438+
* autodetection which can cause it to interpret valid image files as HTML
439+
* and potentially execute JavaScript, creating a cross-site scripting
440+
* attack vectors.
441+
*
442+
* Returns true if IE is likely to mistake the given file for HTML.
443+
*
444+
* @param string $filename
445+
* @return bool
446+
*/
447+
function triggersIEbug( $filename ) {
448+
$file = fopen( $filename, 'rb' );
449+
$chunk = strtolower( fread( $file, 200 ) );
450+
fclose( $file );
451+
452+
$tags = array( '<html', '<head', '<body', '<script' );
453+
foreach( $tags as $tag ) {
454+
if( false !== strpos( $chunk, $tag ) ) {
455+
return true;
456+
}
457+
}
458+
return false;
459+
}
421460
}
422461
?>

0 commit comments

Comments
 (0)