When the code for checking mime types was removed from Drupal, a few lines seem to have been overlooked. These lines add the .txt extension to any file whose mime type has not been identified. As a result, Drupal is adding .txt to every upload, whether JPEG, HTML, PDF, or PNG. This makes uploaded files unusable.

I understand from issue 43220 that we are waiting for someone to come up with a mime type checking solution that reliably works. Until then, the overlooked lines should be removed as well. The attached patch removes them in the CVS and 4.7 branches.

Comments

darren oh’s picture

StatusFileSize
new789 bytes

Patch for 4.6 branch.

darren oh’s picture

It might be preferable to comment out the lines instead of removing them so they can be restored easily when a mime type checking solution is provided. A patch to do so is available in issue 74542.

beginner’s picture

Can you review this patch:
http://drupal.org/node/76154

beginner’s picture

Status: Needs review » Reviewed & tested by the community
dries’s picture

I'd like to have Morbus' blessing for this one.

drumm’s picture

Status: Reviewed & tested by the community » Needs review
morbus iff’s picture

[00:32] <drumm> MorbusIff: around?
[00:32] <MorbusIff> not really.
[00:33] <MorbusIff> something quick?
[00:33] <drumm> MorbusIff: know about http://drupal.org/node/78807?
[00:33] <MorbusIff> no. i have to remember it.
[00:33] <drumm> MorbusIff: apparently your blessing is needed.
[00:33] <MorbusIff> i don't recall me actually having much to do with the mime removal, much past "i agree with chx".
[00:33] <MorbusIff> yes, i know. it's in my inbox.
[00:34] <MorbusIff> i'm quite busy nowadays, so it'll be a bit before i can give it some thought.
[00:34] <MorbusIff> i know that i'm certainly unable to duplicate it.
[00:34] <drumm> MorbusIff: forward it to chx if that is what is needed. and comment in the issue
[00:34] <MorbusIff> and that, thereotically, our newly added file munging would cover anything malicious that that doesn;t.
[00:34] <MorbusIff> but, again, i haven't given it much thought yet.
[00:36] <drumm> MorbusIff: thanks. Please post a follow up to the issue saying what you just did

Steven’s picture

Status: Needs review » Needs work

Well, there are two checks in there... one is to make sure we don't upload files that the server will execute (e.g. .php, .asp, .pl, ...), the other part is to make sure no javascript files are snuck to the browser side without a .txt extension to prevent their execution.

The server-side check needs to stay in core.

The client-side check is now pretty useless because we depend on the honesty of the browser/client to submit the right mime type. Perhaps we could simply put ".js" in the list of files we add a .txt extension to?

darren oh’s picture

Status: Needs work » Needs review

I don't see the server-side check you refer to in the current code. Isn't that what was removed? And isn't it because it was removed that we now find .txt appended to every file name?

darren oh’s picture

Found: mime type checking removed (partially) in CVS commit 26881.

dries’s picture

Darren: does that mean the code needs more work or?

darren oh’s picture

Status: Needs review » Reviewed & tested by the community

What it means is that this patch is ready to be committed "until a better fix comes along." This patch completes the patch committed in CVS commit 26881.

Steven’s picture

if (((substr($file->filemime, 0, 5) == 'text/' || strpos($file->filemime, 'javascript')) && (substr($file->filename, -4) != '.txt')) || preg_match('/\.(php|pl|py|cgi|asp)$/i', $file->filename)) {

The bold part is the server-side check.

Steven’s picture

Status: Reviewed & tested by the community » Needs work
darren oh’s picture

Status: Needs work » Needs review
StatusFileSize
new704 bytes

Tried to remove just the mime type part of the check and add .js to the list of file extensions. Please review.

darren oh’s picture

I tested the patch on my site and it works as expected.

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)