The issue here is that CodeIgniter seems to have a slight bug with its uploader and I agree with @bearfriend.
The is_allowed_filetype()
function of the Upload Library allows a parameter of $ignore_mime
but this parameter is not supplied within the do_upload
function. So my solution is turn mime detection off and (dare I say it) amend the core Upload class so that the file upload check looks like this:
if ( ! $this->is_allowed_filetype($this->detect_mime ? false : true))
** The inverse of your detect_mime parameter is required
There is (unfortunately) another security issue here however. The user could rename virus.exe to allowed.jpg and the file would still be allowed. How bad that is will depend on file permissions and what you're using the files for along with how the files will be used. I for example tried the idea here (https://www.bleepingcomputer.com/forums/t/573945/this-looks-new-and-slipped-by-the-gmail-filters-this-morning/#entry3687679) and it didn't load because it was not a valid image. Different OS may be different.
The other issue with my solution is should you decide to upgrade CI these changes will be lost (although maybe improved by a later release).
Oh and also CI doesn't then ever set $this->file_type
with ignore_mime
true. The solution if you require the file_type in the output after the upload would be to use your own variable name instead (as opposed to sticking with ignore_mime).