MediaWiki REL1_31
|
This class simulates Microsoft Internet Explorer's terribly broken and insecure MIME type detection algorithm. More...
Public Member Functions | |
__construct () | |
constructor | |
getMimesFromData ( $fileName, $chunk, $proposed) | |
Get the untranslated MIME types for all known versions. | |
getRealMimesFromData ( $fileName, $chunk, $proposed) | |
Get the MIME types from getMimesFromData(), but convert the result from IE's idiosyncratic private types into something other apps will understand. | |
translateMimeType ( $type) | |
Translate a MIME type from IE's idiosyncratic private types into more commonly understood type strings. | |
Protected Member Functions | |
getDataFormat ( $version, $type) | |
getMimeTypeForVersion ( $version, $fileName, $chunk, $proposed) | |
Get the MIME type for a given named version. | |
sampleData ( $version, $chunk) | |
Do heuristic checks on the bulk of the data sample. | |
Protected Attributes | |
$addedTypes | |
Changes to the type table in later versions of IE. | |
$baseTypeTable | |
Relevant data taken from the type table in IE 5. | |
$registry | |
An approximation of the "Content Type" values in HKEY_CLASSES_ROOT in a typical Windows installation. | |
$typeTable = [] | |
Type table with versions expanded. | |
$versions = [ 'ie05', 'ie06', 'ie07', 'ie07.strict', 'ie07.nohtml' ] | |
IE versions which have been analysed to bring you this class, and for which some substantive difference exists. | |
Private Member Functions | |
checkBinaryHeaders ( $version, $chunk) | |
Check for binary headers at the start of the chunk Confirmed same in 5 and 7. | |
checkTextHeaders ( $version, $chunk) | |
Check for text headers at the start of the chunk Confirmed same in 5 and 7. | |
This class simulates Microsoft Internet Explorer's terribly broken and insecure MIME type detection algorithm.
It can be used to check web uploads with an apparently safe type, to see if IE will reinterpret them to produce something dangerous.
It is full of bugs and strange design choices should not under any circumstances be used to determine a MIME type to present to a user or client. (Apple Safari developers, this means you too.)
This class is based on a disassembly of IE 5.0, 6.0 and 7.0. Although I have attempted to ensure that this code works in exactly the same way as Internet Explorer, it does not share any source code, or creative choices such as variable names, thus I (Tim Starling) claim copyright on it.
It may be redistributed without restriction. To aid reuse, this class does not depend on any MediaWiki module.
Definition at line 27 of file IEContentAnalyzer.php.
IEContentAnalyzer::__construct | ( | ) |
constructor
Definition at line 315 of file IEContentAnalyzer.php.
References $addedTypes, and $baseTypeTable.
|
private |
Check for binary headers at the start of the chunk Confirmed same in 5 and 7.
string | $version | |
string | $chunk |
Definition at line 586 of file IEContentAnalyzer.php.
Referenced by getMimeTypeForVersion().
|
private |
Check for text headers at the start of the chunk Confirmed same in 5 and 7.
string | $version | |
string | $chunk |
Definition at line 560 of file IEContentAnalyzer.php.
Referenced by getMimeTypeForVersion().
|
protected |
string | $version | |
string | null | $type |
Definition at line 839 of file IEContentAnalyzer.php.
References $type.
Referenced by getMimeTypeForVersion().
IEContentAnalyzer::getMimesFromData | ( | $fileName, | |
$chunk, | |||
$proposed ) |
Get the untranslated MIME types for all known versions.
string | $fileName | the file name (unused at present) |
string | $chunk | the first 256 bytes of the file |
string | $proposed | the MIME type proposed by the server |
Definition at line 376 of file IEContentAnalyzer.php.
References getMimeTypeForVersion().
Referenced by getRealMimesFromData().
|
protected |
Get the MIME type for a given named version.
string | $version | |
string | $fileName | |
string | $chunk | |
string | $proposed |
Definition at line 392 of file IEContentAnalyzer.php.
References $ext, $type, checkBinaryHeaders(), checkTextHeaders(), getDataFormat(), and sampleData().
Referenced by getMimesFromData().
IEContentAnalyzer::getRealMimesFromData | ( | $fileName, | |
$chunk, | |||
$proposed ) |
Get the MIME types from getMimesFromData(), but convert the result from IE's idiosyncratic private types into something other apps will understand.
string | $fileName | the file name (unused at present) |
string | $chunk | the first 256 bytes of the file |
string | $proposed | the MIME type proposed by the server |
Definition at line 338 of file IEContentAnalyzer.php.
References getMimesFromData().
|
protected |
Do heuristic checks on the bulk of the data sample.
Search for HTML tags.
string | $version | |
string | $chunk |
Definition at line 687 of file IEContentAnalyzer.php.
Referenced by getMimeTypeForVersion().
IEContentAnalyzer::translateMimeType | ( | $type | ) |
Translate a MIME type from IE's idiosyncratic private types into more commonly understood type strings.
string | $type |
Definition at line 350 of file IEContentAnalyzer.php.
References $type.
|
protected |
Changes to the type table in later versions of IE.
Definition at line 55 of file IEContentAnalyzer.php.
Referenced by __construct().
|
protected |
Relevant data taken from the type table in IE 5.
Definition at line 31 of file IEContentAnalyzer.php.
Referenced by __construct().
|
protected |
An approximation of the "Content Type" values in HKEY_CLASSES_ROOT in a typical Windows installation.
Used for extension to MIME type mapping if detection fails.
Definition at line 67 of file IEContentAnalyzer.php.
|
protected |
Type table with versions expanded.
Definition at line 312 of file IEContentAnalyzer.php.
|
protected |
IE versions which have been analysed to bring you this class, and for which some substantive difference exists.
These will appear as keys in the return value of getRealMimesFromData(). The names are chosen to sort correctly.
Definition at line 307 of file IEContentAnalyzer.php.